富贵资源网 Design By www.hznty.com

效果:

JS小功能(offsetLeft实现图片滚动效果)实例代码

代码:

复制代码 代码如下:
<head runat="server">
    <title></title>
    <style type="text/css">
        #div1
        {
            width: 245px;
            height: 150px;
            background: red;
            margin: 250px;
            margin-left: 500px;
            position: absolute;
            overflow: hidden;
        }
        #div1 ul li
        {
            float: left;
            width: 44px;
            height: 66px;
            margin-top: 20px;
            margin-right: 5px;
            list-style: none;
        }
        #div1 ul
        {
            width: 250px;
            position: absolute;
            padding: 0;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var oul = document.getElementsByTagName('ul')[0];
            var odiv = document.getElementById('div1');
            var ali = document.getElementsByTagName('li');
            oul.innerHTML = oul.innerHTML + oul.innerHTML;
            oul.style.width = (ali[0].offsetWidth + 5) * ali.length + 'px';
            function roll() {
                if (oul.offsetLeft <= -oul.offsetWidth / 2) {
                    oul.style.left = '0';
                }
                oul.style.left = oul.offsetLeft - 2 + 'px';
            }
            var timer = null;
            timer = setInterval(roll, 30);
            odiv.onmouseover = function () {
                clearInterval(timer);
            }
            odiv.onmouseout = function () {
                timer = setInterval(roll, 30);
            }
        };
    </script>
</head>
<body>
    <div id="div1">
        <ul>
            <li>
                <img src="/UploadFiles/2021-04-02/0.jpg">            <li>
                <img src="../Images/Number1/1.jpg">            <li>
                <img src="/UploadFiles/2021-04-02/2.jpg">            <li>
                <img src="../Images/Number1/3.jpg">            <li>
                <img src="/UploadFiles/2021-04-02/4.jpg">        </ul>
    </div>
</body>

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com