jQuery實現的多張圖無縫滾動效果【測試可用】_jquery

來源:互聯網
上載者:User

本文執行個體講述了jQuery實現的多張圖無縫滾動效果。分享給大家供大家參考,具體如下:

<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>slider</title><style>*{  padding: 0;  margin: 0;}li{  list-style-type: none;}body{  margin: 50px;}.wrap{  border: 3px solid #f00;  width: 600px;  height: 200px;  position: relative;  overflow: hidden;}.wrap ul{  overflow: hidden;  position:absolute;  width: 1600px;  left: 0;  top: 0;  _height:1px;}.wrap ul li{  float: left;  width: 200px;}</style></head><body><a href="javascript:;" class="goLeft">向左走</a><a href="javascript:;" class="goRight">向右走</a><div class="wrap">  <ul>    <li><img src="1.jpg" alt=""></li>    <li><img src="2.jpg" alt=""></li>    <li><img src="3.jpg" alt=""></li>    <li><img src="4.jpg" alt=""></li>    <li><img src="5.jpg" alt=""></li>  </ul></div><script src="jquery-1.7.2.min.js"></script><script src="slider.js"></script></body></html>

slider.js

// 如果想要使一個元素運動起來,一般情況下這個元素須要具有position屬性absolute/relative$(function(){  var oul = $('.wrap ul');  var oulHtml = oul.html();  oul.html(oulHtml+oulHtml)  var timeId = null;  var ali = $('.wrap ul li');  var aliWidth = ali.eq(0).width();  var aliSize = ali.size();  var ulWidth = aliWidth*aliSize;  oul.width(ulWidth); //1600px  var speed = 2;  function slider(){    if(speed<0){      if(oul.css('left')==-ulWidth/2+'px'){      oul.css('left',0);      }      oul.css('left','+=-2px');    }    if(speed>0){      if(oul.css('left')=='0px'){      oul.css('left',-ulWidth/2+'px');      }      oul.css('left','+='+speed+'px');    }   }  // setInterval()函數的作用是:每隔一段時間,執行該函數裡的代碼   timeId = setInterval(slider,30);  $('.wrap').mouseover(function(){    // clearInterval()函數的作用是用來清除定時器    clearInterval(timeId);  });  $('.wrap').mouseout(function(){    timeId = setInterval(slider,30);  });  $('.goLeft').click(function(){    speed=-2;  });  $('.goRight').click(function(){    speed=2;  });});

效果圖如下:

更多關於jQuery相關內容感興趣的讀者可查看本站專題:《jQuery常用外掛程式及用法總結》、《jQuery常見經典特效匯總》、《jQuery form操作技巧匯總》、《jQuery操作json資料技巧匯總》、《jQuery擴充技巧總結》、《jQuery拖拽特效與技巧總結》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結》、《jQuery動畫與特效用法總結》及《jquery選取器用法總結》

希望本文所述對大家jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.