简体   繁体   中英

jQuery: wait for slide to finish before executing code

I want to wait the sliding animation is done before executing the code, as shown below:

$('#blueimp-gallery').on('slide', function (event, index, slide) {
    $(this).find('.modal-citation')
        .text($('#links a').eq(index).data('citation'));
});

I've tried a few ways of doing this, but none of them worked.

$('#blueimp-gallery').on('slide', function (event, index, slide) {
    $(this).find('.modal-citation')
        .text($('#links a').eq(index).data('citation')).delay(3000); // didn't work
});

$('#blueimp-gallery').on('slide', function (event, index, slide) {
    setTimeout(function () {
    $(this).find('.modal-citation')
        .text($('#links a').eq(index).data('citation')); // didn't work
    }, 1000);
});

What is the right way of doing this?

You should be able to set this in the plugin options :

// Callback function executed after the slide change transition.
// Is called with the gallery instance as "this" object and the
// current index and slide as arguments:
onslideend: function() {
 // Do something
}

Taken from : https://github.com/blueimp/Gallery/blob/master/README.md#event-callbacks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM