I want the notify to occur only after the unblock event, however both occur together. I am pretty new to JQuery.
function isSuccess()
{
$(function () {
setTimeout('unblock()',1000);
$.notifyBar({
html: "Thank you, your settings were updated!",
delay: 2000,
animationSpeed: "normal"
});
});
}
asked Oct 5, 2010 at 6:20
Zo Has
13.1k24 gold badges93 silver badges151 bronze badges
4 Answers 4
$(function () {
setTimeout(function() {
unblock();
$.notifyBar({
html: "Thank you, your settings were updated!",
delay: 2000,
animationSpeed: "normal"
});
}, 1000);
});
answered Oct 5, 2010 at 6:24
Darin Dimitrov
1.0m277 gold badges3.3k silver badges3k bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Zo Has
Thanks Andy, can you tell me why did my code did not worked and yours did. I thought first setTimeout would last for 1 second, then the notify bar would occur but they both occured simultaneously, Popo.
Darin Dimitrov
setTimeout doesn't last for 1 second. It waits one second before executing the method without blocking meaning that it will immediately call the notifyBar function. One second later the unblock will be called and 2 seconds later the notify bar. With the new code, we wait 1 second, then we unblock and 2 seconds later we show the notification bar.If you want notifyBar to be executed after unblock, place it after unblock
setTimeout(function() {
unblock();
$.notifyBar({
...
});
},1000);
answered Oct 5, 2010 at 6:23
Nikita Rybak
68.2k22 gold badges163 silver badges183 bronze badges
2 Comments
Zo Has
Thanks Nikita, would'nt it delay the notify by 1 sec also since its included in setTimeOut ?
Nikita Rybak
@Popo Darin has clarified it in his comment
wrap in another anonymous function
function isSuccess()
{
$(function () {
function unblockAndNotify() {
unblock();
$.notifyBar({
html: "Thank you, your settings were updated!",
delay: 2000,
animationSpeed: "normal"
});
}
setTimeout(unblockAndNotify,1000);
});
}
EDIT: I was going to do what Darin did and declare the function inline with the setTimeout, but didn't want to introduce too many new concepts at once.
answered Oct 5, 2010 at 6:24
Luke Schafer
9,2762 gold badges30 silver badges29 bronze badges
Comments
You need to re-arrange the order of calls.
Either you have to call $.notifyBar() from within unblock() or you are doing something like
setTimeout(function(){
unblock();
$.notifyBar({
html: "Thank you, your settings were updated!",
delay: 2000,
animationSpeed: "normal"
});
}, 1000);
answered Oct 5, 2010 at 6:24
jAndy
237k57 gold badges313 silver badges363 bronze badges
Comments
lang-js