Wait for jQuery show() to finish before continuing function?

五迷三道 提交于 2020-01-02 03:48:11

问题


I can't make my div visible with the jquery show() until my function is over! It actually works in IE/FF but not in Chrome. How can I make sure my element is visible before continuing with my function?

Here's my code:

function doOperation(){
    $("#progressbar_area").show();
    (...)
}

回答1:


Add a callback to show:

$("#progressbar_area").show(speed, function() {});

The callback function will be called when the animation is complete.




回答2:


IMO, it would be better to put the rest of your function in the callback parameter to show:

$("#progressbar_area").show("fast", function() {...} );

The caveat here is that the callback is fired (separately) for each element that is in the selector. Fine if you are only showing one item, though.



来源:https://stackoverflow.com/questions/1031470/wait-for-jquery-show-to-finish-before-continuing-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!