var count = 15;
var timerID = 0;
$("button").click(function() {
$('div#test').hide().delay(200).fadeIn('slow', function() {
timerID = setInterval(function() {countDown();}, 1000); // count every 1000 ms, change this to whatever you want
});
$("#wait").show(); // or you could fade this in if you want. Maybe that's what you intended with #test.
});
function countDown() {
count--;
$("#count").text(count);
// do whatever you want to do with your count
if (count <= 0) {
clearInterval(timerID);
}
}
HTML:
<p id="wait" style="display:none">Please wait<span id="count">15</span> seconds...</p>
假設你想在淡入後開始倒計數。否則,只需將該部分拉出,並在淡入淡出線之後插入setInterval,以便在首次單擊按鈕時開始倒計時。
之後,要做到你想要的只是將div fadeIn移動到countDown函數,這很有幫助! –
@Michaelroshdy:我很高興它幫助你。 – defau1t