循环精灵图

 

<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2022/7/22
  Time: 16:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <title>Title</title>
    <style>
     div{
         width: 250px;
         margin:100px auto;
     }
     li{
         list-style-type: none;
     }
      div ul li{
          float: left;
            width: 24px;
            height:24px;
          background-color: aquamarine;
          margin: 15px;
          background: url("images/精灵图.png") no-repeat;
        }
    </style>

</head>
<body>
<div >
    <ul>
        <li ></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>

</div>
<script>
    var lis=document.querySelectorAll('li');
    for(var i=0;i<lis.length;i++){
        var index=i*51;
        lis[i].style.backgroundPosition='-6 -'+index+'px';
    }
</script>
</body>
</html>

 

 

效果图如下:

posted @ 2022-07-24 21:43  晓葡萄在路上  阅读(44)  评论(0)    收藏  举报