MiDo
MiDo

Reputation: 67

Delay function doesn't work on .removeClass()

I'm making my own slider using Jquery, There're 2 buttons to navigate through the sliders (next button) and (previous button)

I made on('click') event on the next button to make my operations on the slider

first of all i got the active slider animated it to go to left by -3500px then i want to remove the active class from it but when i use removeclass the class is removed without the animation

$('.header .next-slider').on('click', function() {

$('.header .sliders .slider.active').animate({
                left:-3500
            },1000).delay(4000).removeClass('active').next().css({
                right:-3500
            }).addClass('active').animate({
                right:0
            },1000);
});

The slider disappear before showing animation.. it should show animation then disappear

Upvotes: 1

Views: 80

Answers (1)

fylzero
fylzero

Reputation: 461

jQuery's delay function only works with animations. However, you could use a setTimeout once the animation is complete.

$('#clickme').click(function() {
    $('#thing').animate({
        left: -3500px
    }, 1000, function() {
        setTimeout(function() {
            $('#thing').removeClass('active');
        }, 3000);
    });
});

Upvotes: 1

Related Questions