<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<link rel="stylesheet" href="./src/demo.css">
<style>
*{
margin:0;
padding:0;
}
li{
box-sizing: border-box;
float: left;
width:10px;
height: 10px;
border:1px solid black;
}
ul{
list-style: none;
width:200px;
height: 200px;
}
</style>
</head>
<body>
<ul>
<li img-date='0'></li> //此处省略399个li标签
</ul>
<script type="text/javascript">
var ul =document.getElementsByTagName('ul')[0];//将ul都取出来
//将li通过target选中
ul.onmouseover = function(e){
var event = e || window.event;
var target = event.target ||event.srcElement;
target.style.backgroundColor = "rgb(0,255," + target.getAttribute('img-date')+")";
target.setAttribute('img-date',parseInt(target.getAttribute('img-date'))+200);
}
//当鼠标滑过的时候样式
</script>
</body>
</html>
效果可自行复制代码执行: