1 回答
TA贡献1841条经验 获得超3个赞
将文本移动到网格顶部并mix-blend-mode: lighten;在 CSS 中使用。看看这个实时片段:
let titlePage = document.querySelector("#title-grid-ctn");
createTitleGrid();
function createTitleGrid() {
for (i = 0; i < Math.pow(10, 2); i++) {
const titleGrid = document.createElement("div");
titleGrid.classList.add("title-grid");
titlePage.appendChild(titleGrid);
}
}
function rdmNumber() {
return Math.floor(Math.random() * 255);
}
const titleGrid = titlePage.querySelectorAll(".title-grid");
titleGrid.forEach((titleGrid, i) => {
titleGrid.animate(
[
{
backgroundColor: 'red',
},
{
backgroundColor: 'blue',
},
],
{
duration: 2000,
iterations: Infinity,
delay: -i * 1000,
easing: "linear",
direction: "alternate",
}
);
});
body {
margin: 0;
}
#title-pg {
position: relative;
}
#title-grid-ctn {
display: flex;
flex-wrap: wrap;
}
.title-grid {
width: 1.5em;
height: 1.5em;
display: inline-block;
}
#title {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #fff;
font: 900 4em sans-serif;
margin: 0;
mix-blend-mode: lighten;
display: flex;
align-items: center;
justify-content: center;
}
<div id="title-pg">
<div id="title-grid-ctn"></div>
<h1 id="title">etch-a-sketch</h1>
</div>
添加回答
举报