Javascript 当我点击最后一个进度按钮时&;当进度结束时,滑块不会返回开始位置,而是消失?
我想知道是否有人能帮忙,我有一个密码笔:- 一切正常,除了当你点击最后一个按钮时,它不会像它应该做的那样过渡到开始或第一个按钮和滑块 我的代码如下,如果有人能帮忙,那就太好了:-Javascript 当我点击最后一个进度按钮时&;当进度结束时,滑块不会返回开始位置,而是消失?,javascript,jquery,sass,Javascript,Jquery,Sass,我想知道是否有人能帮忙,我有一个密码笔:- 一切正常,除了当你点击最后一个按钮时,它不会像它应该做的那样过渡到开始或第一个按钮和滑块 我的代码如下,如果有人能帮忙,那就太好了:- //homepage slider $(document).ready(function(){ // set variables length / timeline / items // var duration = 5, var currentindex = Math.round(Math.ran
//homepage slider
$(document).ready(function(){
// set variables length / timeline / items
// var duration = 5,
var currentindex = Math.round(Math.random()*(3-1)+1),
totalitems = $('.info').length,
timeline = new TimelineMax(),
item,
bar,
duration;
function runslide() {
item = $('[data-id='+ currentindex +']');
bar = item.find('.bar');
duration = parseInt(item.data('duration'));
item.addClass('active');
// if window is more than 768px run timer else pause (this is according to spec)
if ($(window).width() > 769) {
timeline.play();
timeline
.to(bar, 0, {left: '-100%'})
.to(bar, duration, {left: '0%', ease: Linear.easeNone, delay: .75, onComplete: function(){
item.addClass('fadeout');
}})
.to(bar, duration/10, {left: '100%', ease: Power4.easeIn, delay: .25, onComplete: function(){
if(currentindex === totalitems){
currentindex = 1;
} else {
currentindex++;
}
item.removeClass('active fadeout');
timeline.clear();
runslide();
}});
}
}
// progress bar and click slide bar
function clickslide(e) {
currentindex = e;
timeline.clear();
TweenMax.to(bar, duration/10, {left: '0%', ease: Power4.easeOut});
TweenMax.to(bar, duration/10, {left: '100%', ease: Power4.easeIn, delay: duration/10});
$('.photo, .info').removeClass('active fadeout');
runslide();
}
$('.slider-banner')
.on('click', '.info:not(.active, .fadeout)', function(){
clickslide($(this).attr('data-id'));
timeline.pause();
})
.on('mouseover', '.info.active:not(.fadeout)', function(){
timeline.pause();
})
.on('mouseout', '.info.active:not(.fadeout)', function(){
timeline.play();
});
$('.photo').each(function(){
$(this).css({'background-image': 'url('+ $(this).attr('data-image') +')'});
});
// run on window load
$(window).on('load', function(){
runslide();
});
});
$(this).attr('data-id')
返回一个字符串,您正在将单击幻灯片(e)
函数中的currentindex设置为该值
之后,您将在runslide()函数中使用来比较currentindex,因此它将跳转到else条件,因为4!='4'
在else条件下,currentindex++
将“4”转换为4并递增,因此该值为5,并且currentindex变量在每次调用runslide()
时都会不断递增
您可以使用parseInt()
解析从数据属性获得的字符串,也可以使用=
比较值。谢谢!这让我省去了一个头疼的问题:我到底哪里出了错!