views:

131

answers:

2

Hi, I am working on some website , i have used jQuery UI , for pop-up dialog .

I want to close that after 10sec, I have used fadOut 10000 ms but its slowly fades.

Here is the link

View the source code and please help me in this.

+3  A: 

There is a javascript function that allows you to carry out an action after a timeout:

setTimeout('$("#dialog").hide()', 10000);

Usually you're better off passing a function rather than the text to eval()

setTimeout(hideDialog, 10000);

function hideDialog() { $('#dialog').hide(); }

Or, if you want just one line:

setTimeout(function() { $('#dialog').hide(); }, 10000);
Keith
Never quote the first parameter of setTimeout/setInterval, as this invokes "eval()" unnecessarily. Instead, pass an anonymous function or a function reference: setTimeout(doHide, 10000);
Steve Harrison
Fair enough, and good advice - I was going for a quick post an then flesh out approach. Not sure it deserves a -1 though
Keith
Yes, well, I just tried to remove my downvote after you'd edited your post, but StackOverflow seems to have implemented an annoying thing that prevents me from changing my vote now... :(
Steve Harrison
I've already used the setTimeout() approach to hide a dialog in my project already.
Arun P Johny
+4  A: 

Keith's version is a good approach, another, maybe more hacky way, of doing it is this:

$("#modal").animate({opacity:1}, 10000, function() {
    $(this).fadeOut();
});

This way, you can link up everything that needs to be done to the modal in one line...

peirix