JS实现的简单的图片轮换

-----------------------------此种做法是根据网上的做法改版---------------
-----------------------效果展示页:http://hangzhou.mainaer.com/shangchengqu/4.htm-------------------
<div class ="decbL" >
<style type ="text/css" >
.imgsBox {overflow:hidden;width:330px;position:relative;height:200px;}
.clickButton {background-color:#888888;position:absolute;bottom:0;right:0;}
.clickButton a {background-color:#666;border-left:#ccc 1px solid;line-height:15px;height:15px;font-size:12px;float:left;padding:0 7px;text-decoration:none;color:#fff;}
.clickButton a.active,.clickButton a:hover{background-color:#d34600;}
</style >
<div id ="imageSwithContainer" class ="imgsBox" >
<div class ="imgs" ><a href =" # " ><img id ="pic" width ="330" height ="205" ></a ></div >
  <div
 class
="clickButton"
>
<div id ="navBarClickBar4DHZ" ></div >
</div >
</div ><script language ="JavaScript" type ="text/javascript" >
$("#imageSwithContainer").ready(function() {
$.ajax(
{
url:"http://"+location.host+"/Ajax/getProductHotImages.ashx",
type: "GET",
data: { ProID: 4 },
dataType: "json",
success: function(retData) {
if (retData.result == 0){
$("#imageSwithContainer img[@id='pic']").attr("src","http://www.mainaer.com/uploadfiles/mainaer/nopic.gif");

return;
}

var arryImgs = [];
for (var i = 0; i < retData.data.length; i++) {
arryImgs.push(retData.data[i].ImageUrl);
if (i == 0) {
$("<a></a>").attr({ "href": "", "class": "active" }).html(i + 1).appendTo("#navBarClickBar4DHZ");
} else {
$("<a></a>").attr({ "href": "", "class": "" }).html(i + 1).appendTo("#navBarClickBar4DHZ");
}
}
$(".clickButton a").attr("href", "javascript:void();");
var CNT = arryImgs.length+1;
var times = 1;
function changeImage() {
if (times == CNT) {
times = 1;
}
$(".clickButton a").removeClass("active");
$(".clickButton a:nth-child(" + times + ")").addClass("active");
$(".imgs img").attr("src", arryImgs[times - 1]);
times++;
}
var interval = window.setInterval(function() {
changeImage();
}, 1500);
$(".clickButton a").each(function(index) {
$(this).hover(
function() {
$(".clickButton a").removeClass("active");
$(this).addClass("active");
clearInterval(interval);
$(".imgs img").attr("src", arryImgs[index]);
times = index + 1;
},
function() {
interval = window.setInterval(function() {
changeImage();
}, 1500);
}
);
});


}
});
});


</script >
</div >
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值