How to set a minimum delay for BlockUI?
I'm trying to set a minimum display of the BlockUI but having trouble. No matter what value I put in setTimeout, the element is unblocked immediately.
Here I'm setting up the options for the jQuery ajaxForm plugin:
var options = {
type: 'POST',
contentType: 'application/json; charset-utf-8',
dataType: 'js开发者_开发知识库on',
complete: function () {
setTimeout($('#MyElement').unblock(), 5000);
}
};
And here I'm showing the BlockUI on 'MyElement' when my submit button is clicked.
$('.submit').click(function () {
window.showBlockUI($('#MyElement'));
});
Any ideas? Thanks.
You are calling the function in your setTimeout()
, not passing a reference to a function so it executes immediately and passes the return result of that function to setTimeout()
. Thus it executes immediately.
Change it to this:
complete: function () {
setTimeout(function() {$('#MyElement').unblock()}, 5000);
}
or in a little less compact form where you can see it better:
complete: function () {
setTimeout(function() {
$('#MyElement').unblock()
}, 5000);
}
精彩评论