溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

js實(shí)現(xiàn)無(wú)縫滾動(dòng)圖

發(fā)布時(shí)間:2020-10-15 20:44:36 來(lái)源:腳本之家 閱讀:111 作者:漫步未來(lái) 欄目:web開發(fā)

效果如下:

js實(shí)現(xiàn)無(wú)縫滾動(dòng)圖

代碼如下:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <style type = "text/css">
   ul, li { padding: 0; margin: 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;
   }
   .box #right {
   background: url('http://cdn.attach.qdfuns.com/notes/pics/201701/14/042241w8z4hx4m4pjhyjzs.png') no-repeat;
   right: 0;
   }
   #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 timer = null;//管理定時(shí)器
   var leader = 0;
    //1秒之后再開啟定時(shí)器
    timer = setTimeout(function(){
     timer = setInterval(autoAd,30);
    },1000);
   //開啟定時(shí)器
   function autoAd(){   
   leader -=5;
   leader<=-3200?leader = 0:leader;
   ad.style.left = leader +"px";
   }
   //鼠標(biāo)劃入 關(guān)閉定時(shí)器
   ad.onmouseover = function() {   
   clearInterval(timer);
   }
   //鼠標(biāo)離開 開啟定時(shí)器
   ad.onmouseout = function(){
   timer = setInterval(autoAd,20);
   }
   }
  </script>
 </head>
 <body>
  <div class="box">  
  <ul id="ad">
  <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153lscsitwp7sszb6zs.jpg" alt=""></li>
  <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042152pfbkbfe8vbtvulfu.jpg" alt=""></li>
  <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153u3jgn0ds43ndd3dz.jpg" alt=""></li>
  <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042152juuohne22z60hbsb.jpg" alt=""></li>
  <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201701/14/042153lscsitwp7sszb6zs.jpg" alt=""></li>
  </ul>
  <span id="left"></span>
  <span id="right"></span>
  </div>
 </body>
</html>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持億速云!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI