I have this this jquery that loads a success message in a modal:
$('#menu_access').load(
site_url + sUrl,
function() {
$(this).dolPopup(oPopupOptions);
}
);
I want to call this function three seconds after the load:
$('#menu_access').dolPopupHide({});
I'm not sure how to go about it. I'm not too familiar with the .load() function.
You can use jQuery's delay()
method, but you need to add your plugin call to the queue using jQuery's .queue()
method.
$('#menu_access').load(
site_url + sUrl,
function() {
$(this).dolPopup(oPopupOptions);
$(this).delay(3000)
.queue( function( nxt ) {
$(this).dolPopupHide({});
nxt();
});
}
);
Note that the parameter to the function passed to .queue()
needs to be called in order to allow the next animation to occur (at any time).
As an alternative, you can use setTimeout()
, but you need to make sure the value of this
is correct in the callback.
$('#menu_access').load(
site_url + sUrl,
function() {
$(this).dolPopup(oPopupOptions);
var that = this;
setTimeout(function() {
$(that).dolPopupHide({});
}, 3000);
}
);
Here this
is referenced by the variable that
.
Or you could use jQuery's $.proxy()
method to ensure the proper meaning of this
.
$('#menu_access').load(
site_url + sUrl,
function() {
$(this).dolPopup(oPopupOptions);
setTimeout($.proxy(function() {
$(this).dolPopupHide({});
}, this), 3000);
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With