1 Star 0 Fork 0

Tz/OneCasePerDay

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
28-hoverboard.html 2.06 KB
一键复制 编辑 原始数据 按行查看 历史
Tz 提交于 2024-12-02 12:13 . hoverboard
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>hoverboard</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #000;
}
.container {
width: 400px;
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 50px auto;
}
.square {
width: 16px;
height: 16px;
margin: 2px;
background-color: #1d1d1d;
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
transition: all 1s ease;
}
.square:hover {
transition: 0s;
}
</style>
</head>
<body>
<div class="container"></div>
<script>
const container = document.querySelector('.container');
let nums_of_square = 500; // 小方格数量
console.time('代码执行时间'); // 开始计时
for (let i = 0; i < nums_of_square; i++) {
const square = document.createElement('div');
square.classList.add('square');
square.addEventListener('mouseover', () => setColor(square));
square.addEventListener('mouseout', () => removeColor(square));
container.appendChild(square);
}
console.timeEnd('代码执行时间'); // 结束计时并输出结果
const colors = ['#e74c3c', '#8e44ad', '#3498db', '#e67e22', '#2ecc71'];
function setColor(element) {
const color = getRandomColor();
element.style.background = color;
element.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
}
function removeColor(element) {
element.style.background = '#1d1d1d';
element.style.boxShadow = '0 0 2px #000';
}
function getRandomColor() {
return colors[Math.floor(Math.random() * colors.length)];
}
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tizz/one-case-per-day.git
git@gitee.com:tizz/one-case-per-day.git
tizz
one-case-per-day
OneCasePerDay
master

搜索帮助