<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>jQuery 循環(huán)圖片滾動(dòng)切換效果代碼丨龍誠(chéng)互聯(lián)網(wǎng)頁(yè)特效丨lcnt.net</title> <style type="text/css"> *{ margin:0; padding:0;} body{ font-size:12px; color:#000; background:#323232;} li{ list-style:none;} img{ border:none;} .box{ width:380px; margin:20px auto; height:24px; padding-top:144px; background:#000; position:relative; overflow:hidden;} .box ul{ position:absolute; top:10px; left:0; height:114px; width:800px;} .box li{ float:left; margin-left:16px; _display:inline; padding-top:28px; width:80px; height:56px; filter:alpha(opacity=60);-moz-opacity:0.60;opacity:0.60;} .box li.cur{ width:160px; height:114px; padding-top:0; filter:alpha(opacity=100);-moz-opacity:1;opacity:1;} .box li img{ width:100%; height:100%; background:#000;} .box div{ height:24px; line-height:24px;} .box a{ text-decoration:none;font-family:Arial, Helvetica, sans-serif; width:150px; font-weight:900; color:#900;} .box a:hover{ background:#900; color:#fff;} .box .gol{ float:left;text-align:left; padding-left:6px; } .box .gor{ float:right;text-align:right; padding-right:6px; } </style> </head> <body> <br><br> <center>如果不顯示效果,請(qǐng)刷新頁(yè)面。</center> <div class="box" id="box"> <ul> <li><a href="#nogo"><img src="http://www.CsrCode.cn/images/m09.jpg" alt="小雛菊" /></a></li> <li class="cur"><a href="#nogo"><img src="http://www.CsrCode.cn/images/m01.jpg" alt="紅葉傳情" /></a></li> <li><a href="#nogo"><img src="http://www.CsrCode.cn/images/m02.jpg" alt="野花綻放" /></a></li> <li><a href="#nogo"><img src="http://www.CsrCode.cn/images/m03.jpg" alt="往事如茶" /></a></li> <li><a href="#nogo"><img src="http://www.CsrCode.cn/images/m04.jpg" alt="油菜花開(kāi)" /></a></li> </ul> <div> <a href="#nogo" class="gol" id="gol"><<</a> <a href="#nogo" class="gor" id="gor">>></a> </div> </div> <script type="text/javascript" src="http://www.CsrCode.cn/html/txdm_2/images/20100913/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(function(){ trid.init(); }); var trid=new Object(); trid={ li:$("#box li"), licur:$("#box li.cur"), ul:$("#box ul"), len:$("#box li").length, door:true, curidx:1, gol:$("#gol"), gor:$("#gor"), init: function(){ this.format(); this.bindact(); }, format: function(){ var w = (this.len) * 96 + 175 + "px"; this.ul.css({ "width": w }); }, step: function(i){ var self = this; if (!self.door) return false; self.door = false; self.curidx += i; var m = 92 * i; if (i < 0) { if (self.curidx <= -1) { self.curidx += self.li.length; } i = -i; for (var k = 0; k < i; k++) { self.ul.find("li:last").prependTo(self.ul); } self.ul.css({ "margin-left": m + "px" }); self.ul.animate({ "margin-left": "0" }, { duration: 500, complete: function(){ self.door = true; } }); } else if (i > 0) { if (self.curidx >= self.li.length) { self.curidx -= self.li.length; } self.ul.animate({ "margin-left": -m + "px" }, { duration: 500, complete: function(){ for (var k = 0; k < i; k++) { self.ul.find("li:first").appendTo(self.ul); } self.ul.css({ "margin-left": 0 }); self.door = true; } }); } self.display(); }, display: function(){ var self=this; self.licur.animate({ "padding-top":"28px", "width":"80px", "height":"56px", "opacity":"0.6" },{duration:500}); self.li.eq(self.curidx).animate({ "width":"160px", "height":"114px", "padding-top":"0", "opacity":"1.0" },{duration:500, complete:function(){ cur(self.li.eq(self.curidx)); }}); this.licur=this.li.eq(this.curidx); }, bindact: function(){ var self = this; this.gor.bind("click", function(){ self.step(1); $(this).blur(); }); this.gol.bind("click", function(){ self.step(-1); $(this).blur(); }); self.li.bind("click", function(){ if($(this).hasClass("cur")) return; var j = $(this).index() - 1; self.step(j); }); } }
function cur(ele, currentClass, tag){ var ele = $(ele) || ele; var tag = tag || ""; var mark = currentClass || "cur"; ele.addClass(mark).siblings(tag).removeClass(mark); } </script> </body> </html>