国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js實現可控制左右方向的無縫滾動效果

2019-11-20 09:51:57
字體:
來源:轉載
供稿:網友

本文實例為大家分享了無縫滾動效果JavaScript代碼實現,供大家參考,具體內容如下】

效果圖:

實現代碼:

<!DOCTYPE html><html>  <head>    <meta charset="gb2312" />    <title>zzzz</title>    <style>      *{        margin: 0;        padding:0;      }      body{        width: 1000px;        margin: 100px auto;        background-color: #fff;      }      #wrapper{        overflow: hidden;        width: 600px;        height: 100px;        position: relative;               }      #wrapper ul {        position: absolute;        left: 0;        top: 0;      }      #wrapper li{        float: left;        list-style: none;      }      #wrapper li img{        width: 150px;        height: 100px;        border-radius: 9px;      }      input[type=button]{        margin-top: 20px;        width: 35px;         height: 25px;        line-height: 25px;      }    </style>    <script type="text/javascript">      window.onload=function(){        var timer=null;        var speed=4;        var od=document.getElementById("wrapper");        var au=od.getElementsByTagName('ul')[0];        var ali=au.getElementsByTagName('li');        au.innerHTML=au.innerHTML+au.innerHTML;        au.style.width=ali[0].offsetWidth*ali.length+'px';        timer=setInterval(move,30)        function move(){          if(au.offsetLeft<-au.offsetWidth/2){            au.style.left='0';          }          if(au.offsetLeft>0){            au.style.left=-au.offsetWidth/2+'px';          }          au.style.left=au.offsetLeft+speed+'px';        }        od.onmouseover=function(){          clearInterval(timer);        }        od.onmouseout=function(){          timer=setInterval(move,30)        }        document.getElementById("btn1").onclick=function(){          speed=-4;        }        document.getElementById("btn2").onclick=function(){          speed=4;        }      }    </script>  </head>  <body>    <div id="wrapper">      <ul>        <li><img src="img/pic4.jpg"/></li>        <li><img src="img/pic3.jpg"/></li>        <li><img src="img/pic2.jpg"/></li>        <li><img src="img/pic1.jpg"/></li>      </ul>    </div>    <input type="button" name="" id="btn1" value="向左" />    <input type="button" id="btn2" value="向右"/>  </body></html>

大家可以參考以下專題進行學習:

《JavaScript滾動效果匯總》《jQuery滾動效果匯總》 《JavaScript圖片輪播效果匯總》

以上就是本文的全部內容,希望對大家學習JavaScript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇原县| 大渡口区| 客服| 梁河县| 桃园县| 中卫市| 延寿县| 桃园市| 香河县| 余姚市| 乌拉特后旗| 瑞金市| 高雄市| 工布江达县| 自贡市| 浠水县| 叙永县| 盖州市| 天柱县| 宁化县| 高陵县| 临夏县| 兴城市| 康马县| 澄江县| 舒兰市| 新乡市| 屯昌县| 彝良县| 神农架林区| 镇赉县| 临邑县| 盐池县| 吴堡县| 清流县| 舞钢市| 甘谷县| 成安县| 怀宁县| 横峰县| 石门县|