html实现手风琴轮播图,jQuery手风琴轮播图

$(function() {

var imgCounter = 6; //当前轮播图序号

var timer = null;

//初始化,将所有照片有序地放入img盒子里

$('li').each(function(index) {

$(this).css('left', index * 100);

})

function rotation(counter) {

$('li').eq(counter).stop().animate({

left: counter * 100 + 'px' //将点击的图片位置放入到初始化的位置

}, 700);

$('li').eq(counter).nextAll().each(function(index) { //对当前图片的往后的所有图片进行重新定位

$(this).stop().animate({

left: 500 + counter * 100 + index * 100 + 'px' //具体的位置定位,

}, 700)

})

$('li').eq(counter).prevAll().each(function(index) { //对当前图片的往前的所有图片进行重新定位

$(this).stop().animate({

left: (counter - index - 1) * 100 + 'px' //具体的位置定位

}, 700);

})

}

//手风琴轮播主要功能的实现

$('li').mouseenter(function() {

var idx = $('li').index(this); //获取当前点击的图片序号

imgCounter = idx;

rotation(idx);

clearTimeout(timer);

autoRotation();

});

//自动轮播

function autoRotation() {

timer = setTimeout(function() {

if (imgCounter >= 6) {

imgCounter = 0;

} else {

imgCounter++;

}

rotation(imgCounter);

autoRotation();

}, 5000);

}

autoRotation();

})

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值