2014-12-23 57 views
1

我使用jQuery作爲彈出窗口,並且它有一個關閉按鈕。我想讓這個關閉按鈕在30-60秒後出現"wait 60 seconds to close this window"。下面的代碼現在:讓jQuery彈出關閉按鈕出現延遲

var shadow = $('<div id="shadowElem"></div>'); 
var speed = 1000; 
$(document).ready(function() { 
    $('body').prepend(shadow); 
}); 
$(window).load(function() { 
    screenHeight = $(window).height(); 
    screenWidth = $(window).width(); 
    elemWidth = $('#dropElem').outerWidth(true); 
    elemHeight = $('#dropElem').outerHeight(true) 

    leftPosition = (screenWidth/2) - (elemWidth/2); 
    topPosition = (screenHeight/2) - (elemHeight/2); 

    $('#dropElem').css({ 
     'left' : leftPosition + 'px', 
     'top' : -elemHeight + 'px' 
    }); 
    $('#dropElem').show().animate({ 
     'top' : topPosition 
    }, speed); 

    shadow.animate({ 
     'opacity' : 0.7 
    }, speed); 

    $('#dropClose').click(function() { 
     shadow.animate({ 
      'opacity' : 0 
     }, speed); 
     $('#dropElem').animate({ 
     'top' : -elemHeight + 'px' 
    }, speed, function() { 
      shadow.remove(); 
      $(this).remove(); 
     }); 

    }); 
}); 
+0

使用類setTimeout()在一定時間後觸發某些東西。試過了嗎? – trainoasis

回答

0

嘗試(我認爲dropClose是關閉按鈕的id)...

CSS

#dropClose { 
    display: none; 
} 

在打開彈出代碼

setTimeout(function() { 
    $("#dropClose").show(); 
}, 30 * 1000); 
0

DEMO希望這有助於..改變ID與你的ID或你想

你需要你秒= 0後使用的setInterval()和clearInterval()和更改按鈕文本關閉

$(document).ready(function(){  
    var setIt = true; 
    var interval = setInterval(function(){ 
     if(setIt == true){ 
      $('#count span').text($('#count span').text() - 1); 
      if($('#count span').text() == '0'){ 
       $('#count').text('Close This Window'); 
       clearInterval(interval); 
       setIt = false; 
      } 
     } 
    },1000); 
});