编程语言
首页 > 编程语言> > JavaScript: sprite

JavaScript: sprite

作者:互联网

 

 

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      li {
        list-style-type: none;
      }
      .box {
        width: 250px;
        margin: 100px auto;
      }
      .box li {
        float: left;
        width: 24px;
        height: 24px;
        background-color: palegoldenrod;
        margin: 18px;
        background: url(imgs/sprite.png) no-repeat;
      }
    </style>
  </head>
  <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>
      var lis = document.querySelectorAll("li");
      for (let i = 0; i < lis.length; i++) {
        lis[i].style.backgroundPosition = `0 -${i * 44}px`;
      }
    </script>
  </body>
</html>

 

 

标签:style,sprite,JavaScript,li,width,lis,margin,24px
来源: https://www.cnblogs.com/dissipate/p/16383060.html