滚动图片切换实现

html代码

<div id="imgsBox">
	<div class="content_right">
		<div class="ad" >
			<ul class="slider" id="slider">
							       
			</ul>
			<ul class="num" >
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			</ul>
		 </div>
	</div>
</div>

css代码
.content_right{float:left;}
.content_right .ad { 
 margin-bottom:10px;
 width:493px; 
 height:257px; 
 overflow:hidden;
 position:relative;
}
.content_right .slider,.content_right .num{
 position:absolute;
}
.content_right .slider li{ 
 list-style:none;
 display:inline;

}
.content_right .slider img{ 
 width:493px; 
 height:257px;
 display:block;
}
.content_right .num{ 
 right:5px; 
 bottom:5px;
}
.content_right .num li{
 float: left;
 color: #069;
 text-align: center;
 line-height: 16px;
 width: 16px;
 height: 16px;
 font-family: Arial;
 font-size: 12px;
 cursor: pointer;
 overflow: hidden;
 margin: 3px 1px;
 border: 1px solid #069;
 background-color: #fff;
}
.content_right .num li.on{
 color: #fff;
 line-height: 16px;
 width: 16px;
 height: 16px;
 font-size: 14px;
 margin: 3px 1px;
 border: 1px solid #069;
 background-color: #069;
 font-weight: bold;
}
 js代码 
function showActivityImage(cxt){
	$.ajax({
		url:'pbs-psactivity!activityImage.action',
		cache:false,
		async:true,
		type:"POST",
		dataType:'json',
		success:function (lists){
			if(lists != null && lists.length>0){
				for(var i=0;i<lists.length;i++){
					$("#slider").append("<li ><a title=\""+lists[i].title+"\" href=\"pbs-psactivity!lookdetail.action?id="+lists[i].id+"\"><img src=\""+cxt+"/pbs/images/activity/"+lists[i].path+"\" /></a></li>");
				}
			}
		},
		error:function (){
			alert("失败!");
		}
	});
}
$(function(){
	  var len  = $(".num > li").length;
	  var index = 0;
	  var adTimer;
	  $(".num li").mouseover(function(){
		  index  =   $(".num li").index(this);
		  showImg(index);
	  }).eq(0).mouseover(); 
	  //滑入 停止动画,滑出开始动画.
	  $('.ad').hover(function(){
	    	clearInterval(adTimer);
	   },function(){
		    adTimer = setInterval(function(){
		       showImg(index)
		    index++;
		    if(index==len){index=0;}
		     } , 2000);
	  }).trigger("mouseleave");
});
// 通过控制top ,来显示不同的幻灯片
function showImg(index){
	var adHeight = $(".content_right .ad").height();
	$(".slider").stop(true,false).animate({bottom : -adHeight*index},1000);
	$(".num li").removeClass("on").eq(index).addClass("on");
}
  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值