thebird / Swipe

Swipe is the most accurate touch slider.
MIT License
6.79k stars 1.69k forks source link

Automatic advancing of slides stops when slide() method is called. #316

Open peterugh opened 11 years ago

peterugh commented 11 years ago

I have pagination working correctly for my slideshow with the ability to jump to a slide using the slide() method. However, after I manually go to a slide, the autoplay stops working.

I'm using jQuery 1.9.1 although the plugin itself does not require it. See example code below, which performs correctly, moving the slides manually using pagination, but stops autoplay after that is invoked.

P.S. I didn't see this exact issue raised anywhere else.

function buildSwipeNav(){
    var controlsContainer = $("#featured_nav");
    var totalSlides = window.mySwipe.getNumSlides();
    var menuMarkup = '<ul>';
    for(i = 0; i < totalSlides; i++){
        menuMarkup = menuMarkup + '<a href="#" data-slide-index="' + i + '">' + i + '</a>';
    }
    menuMarkup = menuMarkup + '</ul>';
    controlsContainer.html(menuMarkup);
    $('[data-slide-index=0]').addClass('active_slide');
}

function moveSlidesHome(evt){
    evt.preventDefault();
    var slideTarget = $(this).data('slide-index');clicked
    window.mySwipe.slide(slideTarget, 500);
}

function slidHome(index){
    $("#featured_nav a").removeClass('active_slide');
    $('[data-slide-index=' + index + ']').addClass('active_slide');
}

window.mySwipe = new Swipe(document.getElementById('slider'), {
    speed: 500,
    auto: 1000,
    transitionEnd: slidHome
});
buildSwipeNav();
$(document).on('click', '#featured_nav a', moveSlidesHome)
alycda commented 11 years ago

I have the same issue. temp fix by adding mySwipe.start(); after mySwipe.slide(); however it is a little buggy, sometimes jumping 2 slides

trose commented 11 years ago

I've run into the "jump 2 slides" issues as well. I'm investigating further though I believe the double sliding is because begin() is being called twice, or being called when it doesn't need to be. Try adding an additional delay = options.auto || 0 in the slide method for now.

Arguseye commented 7 years ago

Call restart() or start() method in transitionEnd hook can resolve "jump 2 slides" issues.