zoukankan      html  css  js  c++  java
  • JS—萌宠(无缝滚动)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>萌宠</title>
    <style>
    *{
        margin:0px;
        padding:0px;
    }
    #cute
    {
        position:relative;
        1400px;
        height:220px;
        margin-top:100px;
        margin-left:120px;
        overflow:hidden;
    }
    #cute ul
    {
        list-style-type:none;
        left:0px;
        top:0px;
        position:absolute;
    }
    #cute ul li
    {
        float:left;
        margin-left:5px;
    }
    li img
    {
        270px;
        height:220px;
    }
    #right
    {
        float:right;
    }
    </style>
    <script>
    window.onload=function()
    {
        var oCte=document.getElementById('cute');
        var oUl=oCte.getElementsByTagName('ul')[0];
        var aLi=oUl.getElementsByTagName('li');
        var speed=2;
        oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
        oUl.style.width=aLi[0].offsetWidth*aLi.length+50+'px';
        function move()
        {
            if (oUl.offsetLeft<-oUl.offsetWidth/2)
                oUl.style.left='0px';       
            if (oUl.offsetLeft>0)
                oUl.style.left=-oUl.offsetWidth/2+'px';
            oUl.style.left=oUl.offsetLeft+speed+'px';
        }
        var timer=setInterval(move, 30);
        oCte.onmouseover=function()
        {
            clearInterval(timer);
        };
        oCte.onmouseout=function()
        {
            timer=setInterval(move, 30);
        };
        document.getElementById('left').onclick=function()
        {
            speed=-2;
        };
        document.getElementById('right').onclick=function()
        {
            speed=2;
        };
    };
    </script>
    </head>
    <body>
    <div id="left">
    <img src="image/left.jpg"/>
    </div>
    <div id="cute">
        <ul>
            <li><img src="image/a.jpg"/></li>
            <li><img src="image/b.jpg"/></li>
            <li><img src="image/c.jpg"/></li>
            <li><img src="image/d.jpg"/></li>
            <li><img src="image/e.jpg"/></li>
        </ul>
    </div>
    <div id="right">
    <img src="image/right.jpg"/>
    </div>
    </body>
    </html>                    
  • 相关阅读:
    李洪强九宫格的实现
    iOS开发多线程篇 11 —自定义NSOperation
    CALayer3-层的属性
    网络编程小结
    iOS开发多线程篇 10 —NSOperation基本操作
    CALayer2-创建新的层
    iOS开发之多文件上传
    三级联动
    用 ERD 盘解决 Win8 自己主动更新后不能启动的问题
    hdu1028(母函数+DP)
  • 原文地址:https://www.cnblogs.com/syhandll/p/5042940.html
Copyright © 2011-2022 走看看