png图片入下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
li{
list-style: none;
}
.box{
width: 250px;
margin: 100px auto;
}
.box li{
float: left;
width: 24px;
height: 24px;
background-color: pink;
margin: 15px;
background: url('1.png') no-repeat;
}
</style>
<body>
<div class="box">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script type="text/javascript">
//1.获取元素 所有的小li
var lis = document.querySelectorAll('li');
for(var i = 0;i < lis.length;i++){
//让索引号 乘以44就是每个li的背景y坐标
var index = i * 44;
lis[i].style.backgroundPosition = '0 -' + index + 'px';
}
</script>
</body>
</html>