jquery實現圖片左右切換的方法,jquery實現圖片切換

來源:互聯網
上載者:User

jquery實現圖片左右切換的方法,jquery實現圖片切換

本文執行個體講述了jquery實現圖片左右切換的方法。分享給大家供大家參考。具體實現方法如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>圖片左右滾動</title><script src="jquery-1.6.2.min.js" type="text/javascript"></script><script>$(function(){ var i=0; var li = $(".lxfscroll li"); var n=li.length-1; var speed = 300; li.not(":first").css({left:"400px"}); li.eq(n).css({left:"-400px"}); lxfNext=function (){ if (!li.is(":animated")) {  if (i>=n){i=0;li.eq(n).animate({left:"-400px"},speed);  li.eq(i).animate({left:"0px"},speed);  }else{i++;li.eq(i-1).animate({left:"-400px"},speed);li.eq(i).animate({left:"0px"},speed);};  li.not("eq(i)").css({left:"400px"});  $("i").text(i+1); }else{}; }; lxfLast=function (){ if (!li.is(":animated")) {  if (i<=0){i=n;li.eq(0).animate({left:"400px"},speed);li.eq(n).animate({left:"0px"},speed);  }else{i--;li.eq(i+1).animate({left:"400px"},speed);li.eq(i).animate({left:"0px"},speed);}  li.not("eq(i)").css({left:"-400px"});  $("i").text(i+1); }; };});</script><style type="text/css">* { font-size:12px; color:#333; text-decoration:none; padding:0; margin:0; list-style:none; font-style: normal; font-family: Arial, Helvetica, sans-serif;}.lxfscroll { width:400px; margin-left:auto; margin-right:auto; margin-top: 20px; overflow: hidden; position: relative; height: 300px; border: 1px dashed #CCC;}.button { margin-right:auto; margin-left:auto; width:400px; text-align:center; padding-top: 10px;}i { color:#F00; font-weight:bold;}.button input { padding-top: 4px; padding-right: 12px; padding-bottom: 4px; padding-left: 12px;}.lxfscroll ul li { height: 300px; width: 400px; text-align: center; line-height: 300px; position: absolute; font-size: 40px; font-weight: bold;}</style></head><body><div class="lxfscroll"> <ul>  <li>我是第1張圖片</li>  <li>我是第2張圖片</li>  <li>我是第3張圖片</li>  <li>我是第4張圖片</li>  <li>我是第5張圖片</li>  <li>我是第6張圖片</li>  <li>我是第7張圖片</li>  <li>我是第N張圖片</li> </ul></div><div class="button"><input name="a" type="button" onClick="lxfLast()" value="上一個" /><input name="a" type="button" onClick="lxfNext()" value="下一個" /></div><div class="button">當前顯示的是第 <i>1</i> 張圖片</div></body></html>

希望本文所述對大家的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.