[英]jquery code execution issue in chrome browser
function refreshdata() { $('.overlayloading').toggle(true); fetchData(); }
Here $('.overlayloading').toggle(true)
is executing only after the execution of fetchData()
in chrome. 这里
$('.overlayloading').toggle(true)
仅在chrome中执行fetchData()
之后执行。 Its working fine in Mozilla. 在Mozilla中可以正常工作。 But it's not working in google chrome browser.
但它不适用于谷歌浏览器。 I am trying to load loading animation before the
fetchData
function.But loading animation is showing after the execution of fecthData
function. 我正在尝试在
fetchData
函数之前加载动画,但是在执行fecthData
函数之后显示加载动画。
You can pass a callback to toggle, so it actually waits for the animation to be finished before executing the function. 您可以传递回调以进行切换,因此在执行功能之前,它实际上等待动画完成。
$('.overlayloading').toggle(400,fetchData);
If you want data to be loaded before the animation begins, you could pass the toggle function as callback to your fetchdata or return a promise, which you will use to execute the toggle within then()
如果要在动画开始之前加载数据,则可以将toggle函数作为回调传递给fetchdata或返回promise,您将使用它们在
then()
执行切换
jQuery is making asynchronous animations, javaScript runs on the browser's UI thread, if it was synchronous then the UI would freeze until the animation finishes. jQuery正在制作异步动画,javaScript在浏览器的UI线程上运行,如果它是同步的,则UI将冻结直到动画完成。
What You can do is use the callback
method of .toggle
, it will run after the toggle animation completes. 您可以使用
.toggle
的callback
方法,该方法将在切换动画完成后运行。 Docs 文件
function refreshdata()
$('.overlayloading').toggle("slow", function() {
// Animation complete.
fetchData();
});
});
You can try 你可以试试
function refreshdata() {
$('.overlayloading').toggle(true);
window.requestAnimationFrame(fetchData);
}
to make sure the display toggle actually takes full effect in the view before invoking fetchData
. 以确保在调用
fetchData
之前,显示切换实际上在视图中完全生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.