最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實現(xiàn)無縫滾動圖(可控制當(dāng)前滾動的方向)

 更新時間:2017年02月22日 10:09:44   作者:漫步未來  
本文主要分享了js實現(xiàn)無縫滾動圖的示例代碼,這個版本可以控制左右滾動,鼠標(biāo)點擊對應(yīng)的廣告會自動滑動把廣告完全展示出來,當(dāng)鼠標(biāo)離開,接著繼續(xù)滾動。具有很好的參考價值,下面跟著小編一起來看下吧

這個版本可以控制左右滾動,鼠標(biāo)點擊對應(yīng)的廣告會自動滑動把廣告完全展示出來。還實現(xiàn)了記錄當(dāng)前滾動的方向,當(dāng)鼠標(biāo)離開,接著繼續(xù)滾動?。?!

效果圖:

代碼如下:

<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="utf-8">
 <style type = "text/css">
 *{margin: 0; padding: 0;}
  li { list-style: none; }
  .box {
  width: 800px;
  height: 450px;
  margin: 50px auto;
  overflow: hidden; 
  position: relative;
  }
  .box span {
  width: 40px;
  height: 60px;  
  display: block;
  position: absolute;
  top: 225px;
  margin-top: -20px;
  cursor: pointer;
  z-index: 1;
  }
  .box #left {
 background: url('http://cdn.attach.qdfuns.com/notes/pics/201701/14/042311cbd7gbjd7sggkd2b.png') no-repeat;
 left: 0;
    display: none;
  }
  .box #right {
  background: url('http://cdn.attach.qdfuns.com/notes/pics/201701/14/042241w8z4hx4m4pjhyjzs.png') no-repeat;
  right: 0;
   display: none;
  }
  #ad {
  width: 4000px;
  height: 450px;
  position: absolute;
  }
  #ad li {
 float: left;
  }
 </style>
 <script type = "text/javascript">
  window.onload = function(){
  var ad = document.getElementById("ad");
  var lef = document.getElementById("left");
  var rig = document.getElementById("right");
  var timer = null; //管理定時器
 var aspect = true;
  function animate(obj,speed){
   //關(guān)閉上一個定時器
   clearInterval(obj.timer);
   //管理定時器
 obj.timer = setInterval(autoAd,30);
   function autoAd(){
   //判斷左走或者右走
   if(speed > 0){
    aspect = true;
    if(obj.offsetLeft >= 0){
    obj.style.left = -3200 + 'px';
    }
 }else {
    aspect = false;
    if(obj.offsetLeft <= -3200){
    obj.style.left = 0;
    }
 }
   //勻速動畫: 盒子當(dāng)前的位置 + 步長
   obj.style.left = obj.offsetLeft + speed +"px";
   }
 }
 animate(ad,-5);
 //鼠標(biāo)劃入顯示控制按鈕并關(guān)閉
  ad.parentNode.onmouseover = function(){
   clearInterval(ad.timer);
 lef.style.display = "block";
   rig.style.display = "block";
 };
  //鼠標(biāo)離開隱藏控制按鈕并啟動定時器
  ad.parentNode.onmouseout = function(){
   clearInterval(ad.timer);
   clearInterval(timer);
   lef.style.display = "none";
   rig.style.display = "none";
 if(aspect){
 animate(ad,5);
 }else{
 animate(ad,-5);
 }
  };
  ad.onclick = function(event){
   //關(guān)閉自動輪播定時器
   clearInterval(ad.timer);
   clearInterval(timer);
   var event = event || window.event;
 if(event.target){
   var target = - parseInt(event.target.alt) * 800;
 }else{
   var target = - parseInt(event.srcElement.alt) * 800;
 }
   timer = setInterval(function(){
   var step = (target - ad.offsetLeft) / 10;
   step = step > 0 ? Math.ceil(step):Math.floor(step);
   ad.style.left = ad.offsetLeft + step + "px";
   if(ad.offsetLeft%800 == 0){
    clearInterval(timer);
 }
 },20)
 }
  //右移動
  lef.onclick = function(){
   clearInterval(timer);
   animate(ad,5);
  };
  //左移動
  rig.onclick = function(){
   clearInterval(timer);
 animate(ad,-5);
 };
  }
 </script>
 </head>
 <body>
 <div class="box"> 
 <ul id="ad">
 <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153lscsitwp7sszb6zs.jpg" alt="0"></li>
 <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042152pfbkbfe8vbtvulfu.jpg" alt="1"></li>
 <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153u3jgn0ds43ndd3dz.jpg" alt="2"></li>
 <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042152juuohne22z60hbsb.jpg" alt="3"></li>
 <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153lscsitwp7sszb6zs.jpg" alt="4"></li>
 </ul>
 <span id="left"></span>
 <span id="right"></span>
 </div>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論

犍为县| 佛冈县| 新津县| 惠东县| 承德县| 浏阳市| 织金县| 平安县| 左云县| 德安县| 祁阳县| 惠州市| 玉溪市| 商洛市| 囊谦县| 灵台县| 子长县| 弥渡县| 琼结县| 赣州市| 碌曲县| 剑河县| 新田县| 盘山县| 方山县| 东宁县| 临漳县| 元朗区| 西和县| 东安县| 咸阳市| 湖北省| 南宫市| 洞头县| 宝鸡市| 绥芬河市| 鄂托克前旗| 长海县| 镇康县| 安溪县| 沙雅县|