Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery dialog open and automatically close after 3 seconds

I am trying to open a jQuery dialog with no buttons to display with some animations and then automatically stay there for like 3 seconds, then close. Here is a jsfiddle of what I think should work, but as you can see it just opens and closes without waitng the 3 seconds:

jsfiddle: http://jsfiddle.net/WrdM9/1/

Anyone know how to straighten this out? Thanks!

like image 775
jeffery_the_wind Avatar asked Apr 16 '12 17:04

jeffery_the_wind


3 Answers

You should use setTimeout:

open: function(event, ui) {
    setTimeout(function(){
        $('#dialog').dialog('close');                
    }, 3000);
}

Here's the fiddle: http://jsfiddle.net/WrdM9/2/

like image 194
Joseph Silber Avatar answered Nov 15 '22 17:11

Joseph Silber


Use the jQuery delay function e.g.

$( "#your-modal-id" ).slideDown( 300 ).delay( 800 ).slideUp( 400 );
like image 44
Shao Khan Avatar answered Nov 15 '22 18:11

Shao Khan


If you also want to add some transitions I wouldn't recommend jQuery slideUp and slideDown animations. Those are slow since it uses CPU instead of GPU and the animations themselves don't feel totally right.

I would recommend Velocity.js instead. Remember to also add Velocity UI js. And you could do something like this:

$( "#your-modal-id" ).velocity('transition.slideUpBigOut', { delay: 3000 })
like image 20
Martin Avatar answered Nov 15 '22 18:11

Martin