0

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

4 Answers 4

3
$(function () {
 setTimeout(function() {
 unblock();
 $.notifyBar({
 html: "Thank you, your settings were updated!",
 delay: 2000,
 animationSpeed: "normal"
 });
 }, 1000);
});
answered Oct 5, 2010 at 6:24
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
2

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

2 Comments

Thanks Nikita, would'nt it delay the notify by 1 sec also since its included in setTimeOut ?
@Popo Darin has clarified it in his comment
1

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

Comments

1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.