Callback function to be executed after jQuery show / hide?

前端 未结 2 789
情歌与酒
情歌与酒 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: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.

提交回复
热议问题