zoukankan      html  css  js  c++  java
  • js 循环精灵图案例

    <!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">
        <title>Document</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
            
            li {
                list-style-type: none;
            }
            
            .box {
                 250px;
                margin: 100px auto;
            }
            
            .box li {
                float: left;
                 24px;
                height: 24px;
                background-color: pink;
                margin: 15px;
                background: url(images/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>
            // 1  获取元素
            var lis = document.querySelectorAll('li');
            for (var i = 0; i < lis.length; i++) {
                var index = i * 44;
                lis[i].style.backgroundPosition = '0  -' + index + 'px';
            }
        </script>
    </body>

    </html>
  • 相关阅读:
    HTML 标签
    HTML与CSS的关系
    用node搭建本地服务环境
    Windows平台下SVN安装配置及使用
    CSS Flex布局整理
    zepto 选中select option 的值
    Zepto tap 穿透bug、解决移动端点击穿透问题
    jquery 上下滚动显示隐藏
    es6学习笔记二:生成器 Generators
    es6学习笔记一:迭代器和for-of循环
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/13050974.html
Copyright © 2011-2022 走看看