jQuery 循环图片滚动,这里请注意jQuery版本,1.3用以前版本可能会使本效果变差,最后用1.4以上版本,从官方说明看,jQuery1.4与1.3还是存在一些差别的。循环图片滚动用jQuery去实现是比较方便的,其效果大致另人满意。
<!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 循环图片滚动切换效果代码丨芯晴网页特效丨CsrCode.Cn</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:600px; 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:20px; 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>如果不显示效果,请刷新页面。</center>
<div class="box" id="box">
<ul>
<li><a href="#nogo"><img src="/images/m09.jpg" alt="小雏菊" /></a></li>
<li><a href="#nogo"><img src="/images/m01.jpg" alt="红叶传情" /></a></li>
<li class="cur"><a href="#nogo"><img src="/images/m02.jpg" alt="野花绽放" /></a></li>
<li><a href="#nogo"><img src="/images/m03.jpg" alt="往事如茶" /></a></li>
<li><a href="#nogo"><img src="/images/m04.jpg" alt="油菜花开" /></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="/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:2,
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() - 2;
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>
<p align="center">本特效由 <a href="http://www.CsrCode.cn">芯晴网页特效</a>丨CsrCode.Cn 收集于互联网,只为兴趣与学习交流,不作商业用途。</p>
效果: