Callback function to be executed after jQuery show / hide?

前端 未结 2 801
情歌与酒
情歌与酒 2021-01-20 23:15

In iOS, the following code has a noticeable flicker between the hide() and the scrollBy():

element.hide();
window.scrollBy(0, -elementHeight);

相关标签:
2条回答
  • 2021-01-20 23:45

    From the jQuery api:

    .hide(options)

    complete Type: Function() A function to call once the animation is complete.

    Try this:

    element.hide({complete: function(){ window.scrollBy(0, -elementHeight); });

    0 讨论(0)
  • 2021-01-20 23:57

    Either pass a duration and a callback, or just pass a callback option, like this:

    element.hide(0, some_function);
    
    // or 
    
    element.hide({done: some_function});
    

    By default, the second option takes 400 ms. To do it immediately, use one of these:

    element.hide(0, some_function);
    
    // or 
    
    element.hide({duration: 0, done: some_function});
    

    Here's a jsFiddle demo.

    See the jQuery documentation for more details.

    0 讨论(0)
提交回复
热议问题