在jQuery show / hide之后执行的回调函数? [英] Callback function to be executed after jQuery show / hide?
问题描述
在iOS中,以下代码在hide()和scrollBy()之间有明显的闪烁:
In iOS, the following code has a noticeable flicker between the hide() and the scrollBy():
element.hide();
window.scrollBy(0, -elementHeight);
这是因为在iOS上切换display:none和display:block是一项繁重的任务,就好像元素被添加到DOM中或从DOM中删除。
This is because toggling between display: none and display: block on iOS is a heavy task, as if the elements are being added to and removed from the DOM.
一旦hide()成功完成,我需要一种方法来执行window.scrollBy()作为回调并且DOM已更新。有没有办法在jQuery中执行此操作?
I need a way to perform window.scrollBy() as a callback, once the hide() has successfully completed and the DOM has updated. Is there a way to do this in jQuery?
推荐答案
要么传递持续时间和回调,要么只传递回调选项,像这样:
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});
默认情况下,第二个选项需要400毫秒。要立即执行此操作,请使用以下方法之一:
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});
这篇关于在jQuery show / hide之后执行的回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!