Мне было интересно, если кто-нибудь может помочь, у меня есть кодекс: -
https://codepen.io/robbiemcmullen/pen/eoQxKJ
Все работает нормально, кроме тех случаев, когда вы нажимаете последнюю кнопку, она не переходит в стартовую или первую кнопку и ползунок, как это должно быть.
Мой код выглядит следующим образом, было бы замечательно, если кто-нибудь может помочь: -
//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();
});
});