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();
});
});
});
使用類setTimeout()在一定時間後觸發某些東西。試過了嗎? – trainoasis