load jquery modal dialog after a delay

六眼飞鱼酱① 提交于 2019-12-25 11:33:48

问题


I would like to load jquery dialog after a delay of few seconds after page load. Here is my code so far.

<div id="dialog" title="My Dialog Title" style="display:none">
<p>This is My Dialog box Description/Content</p>   

    <script type="text/javascript">

    $(document).ready(function() {    
    setTimeout(function(){
      $(function () {
        $("#dialog").dialog({
            show: {
            effect: 'drop',
            direction : 'up',
            distance: 1000,
            duration: 2000,
            },
        });
      });
    }, 2000)
});


</script>

    <style>
.ui-dialog-titlebar {display:none;}
#other_content {width:200px; height:200px;background-color:grey;}
#dialog_content{display:none;}
</style>

The problem is now that the popup animation of sliding from top is good for Chrome but in firefox it does not come to the center of the screen and for IE there is no popup at all.

http://jsfiddle.net/fakhruddin/x39Rr/9/

Please guide.


回答1:


Use setTimeout() to delay.

$(document).ready(function() {    
    setTimeout(function(){

        $("#dialog").dialog({
            show: {
            effect: 'fade',
            duration: 800,
            },
        });

    }, 2000)
});



回答2:


Try this

$(function(){
 $('yourDiv').dialog({
   autoOpen: false
 });
});

function openMyDialog(){
 $('yourDiv').dialog('open');
}

$(document).ready(function(){
 setTimeout(function(){
    openMyDialog();}, 2000);
});

You can use the jquery slidedown/slideup: http://api.jquery.com/slideUp/



来源:https://stackoverflow.com/questions/17305879/load-jquery-modal-dialog-after-a-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!