原生javascript實現圖片無縫滾動效果_javascript技巧

來源:互聯網
上載者:User

圖片水平無縫滾動效果在大量的網站都有應用,特別是一些企業網站在展示產品的時候,因為是動態效果,所以能夠給網站增色不少,相比靜態圖片展示更能夠吸引使用者的注意力,下面就通過執行個體代碼介紹一下如何?此效果。
代碼如下:

<html><head><meta charset="gb2312"><title>雲棲社區</title><style type="text/css"> #demo{  background:#FFF;  overflow:hidden;  border:1px dashed #CCC;  width:500px; } #indemo{ float:left; width:2000px;} #indemo a{ width:100px; height:100px; float:left; background-color:blue; margin-left:5px; text-align:center; line-height:100px; color:red; text-decoration:none;}#demo1{float:left;} #demo2{float:left;} </style><script type="text/javascript"> window.onload=function(){ var speed=10;  var tab=document.getElementById("demo");  var tab1=document.getElementById("demo1");  var tab2=document.getElementById("demo2");  tab2.innerHTML=tab1.innerHTML;  function Marquee(){  if(tab2.offsetWidth-tab.scrollLeft<=0){  tab.scrollLeft-=tab1.offsetWidth  }  else{   tab.scrollLeft++;  }  }  var MyMar=setInterval(Marquee,speed);  tab.onmouseover=function() {clearInterval(MyMar)};  tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)}; } </script></head><body><div id="demo"> <div id="indemo"> <div id="demo1">   <a href="#">雲棲社區一</a>   <a href="#">雲棲社區二</a>   <a href="#">雲棲社區三</a>   <a href="#">雲棲社區四</a>   <a href="#">雲棲社區五</a>   <a href="#">雲棲社區六</a>  </div> <div id="demo2"></div> </div>

希望對大家學習javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.