记录一个简单的小程序,样式效果可以根据自己的喜好设置。
效果示例:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/mouseMove.css">
<title>Document</title>
</head>
<body>
<!-- 设置一个div作为滑动区域 -->
<div id="mouseMovePlace"></div>
<script>
// 使用js自动创建div
var mouseMovePlace=document.getElementById("mouseMovePlace");
for(var x=0;x<100;x++){
var creatediv = document.createElement("div");
mouseMovePlace.appendChild(creatediv);
}
</script>
</body>
</html>
css部分:
#mouseMovePlace{
width: 220px;
height: 220px;
background-color: lightgray;
}
#mouseMovePlace div{
width: 20px;
height: 20px;
margin: 1px;
border-radius: 15%;
background-color:gray;
float: left;
transition: background-color 1s linear;
}
#mouseMovePlace div:hover{
background-color: white;
transition: background-color 100ms linear;
}