so my slider works perfectly fine; switching evey 3 seconds and stopping when i mouse over it or if i click arrows. then it restarts if i leave it alone.
all works fine.
however, when i change resolution to work on responsiveness is starts speeding up and doesnt respond to the mouseover stop.
$var main = function(){
$('.dropdown-toggle').click(function(){
$('.dropdown-menu').toggle();
});
$('.arrow-next').click(function(){
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
if(nextSlide.length == 0){
nextSlide = $('.slide').first();
};
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if(nextDot.length == 0){
nextDot = $('.dot').first();
};
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
};
$('.arrow-prev').click(function(){
currentSlide = $('.active-slide');
prevSlide = currentSlide.prev();
if(prevSlide.length == 0){
prevSlide = $('.slide').last();
};
currentSlide.fadeOut(600).removeClass('active-slide');
prevSlide.fadeIn(600).addClass('active-slide');
var currentDot = $('.active-dot');
var prevDot = currentDot.prev();
if(prevDot.length == 0){
prevDot = $('.dot').last();
};
currentDot.removeClass('active-dot');
prevDot.addClass('active-dot');
});
$(document).ready(main);
$(document).ready( function() {
var auto = setInterval(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
if(nextSlide.length == 0){
nextSlide = $('.slide').first();
};
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if(nextDot.length == 0){
nextDot = $('.dot').first();
};
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
}, 3000);
$('.slider, .arrow-prev, .arrow-next').mouseover(function(){
clearInterval(auto);
}).mouseout(function(){
var auto = setInterval(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
if(nextSlide.length == 0){
nextSlide = $('.slide').first();
};
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if(nextDot.length == 0){
nextDot = $('.dot').first();
};
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
}, 3000);
})
});
I figured it out... since I declared "var" inside function it was a not global variable and so it stacked. Now i added var auto outside the function and removed var inside functions and it works perfectly with resize; minimize, and everything :D
i started looking at js and jquery about 3 weeks ago and had 0 knowledge prior so my code may be...how to say it...le crap! but at least I am happy I figured this one out!
I welcome advice in general about this slider.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.