我正在使用 - http://github.com/rendro/countdown/
要进行倒计时,执行它的JS是:
$( function()
{
// Add background image
$.backstretch('images/road2.jpg');
var endDate = "December 17, 2015 11:33:00";
$('.countdown.simple').countdown({ date: endDate });
$('.countdown.styled').countdown(
{
date: endDate,
render: function(data)
{
$(this.el).html("<div>" + this.leadingZeros(data.days, 3) + " <span>days</span></div><div>" + this.leadingZeros(data.hours, 2) + " <span>hrs</span></div><div>" + this.leadingZeros(data.min, 2) + " <span>min</span></div><div>" + this.leadingZeros(data.sec, 2) + " <span>sec</span></div>");
}
});
$('.countdown.callback').countdown({
date: +(new Date) + 10000,
render: function(data)
{
$(this.el).text(this.leadingZeros(data.sec, 2) + " sec");
},
onEnd: function()
{
alert("Done");
$(this.el).addClass('ended');
}
}).on("click", function()
{
$(this).removeClass('ended').data('countdown').update(+(new Date) + 10000).start();
});
});
倒计时每次都有效,但我从来没有得到我想要的警报。
如何在倒计时结束时触发事件?
答案 0 :(得分:1)
您的onEnd
回调放错了地方。这样做
$('.countdown.simple').countdown({ date: endDate,
onEnd: function()
{
alert("Done");
$(this.el).addClass('ended');
}
});