我正在寻找一个jquery倒计时时钟或计时器开始与声音播放时,一个日期已经设置。我发现很多网站都有jquery倒计时的例子,但是当开始计数时没有声音播放…
如何添加声音到Jquery倒计时计时器??
感谢更新:这是mootool定时器http://jsfiddle.net/QH6X8/185/
的演示,我想使用声音播放!知道怎么做吗?HTML代码:
<div id="countdown"></div>
, mootool代码为;
var end = new Date('16 May 2013 13:29:00'); // set expiry date and time..
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24
var timer;
function showRemaining()
{
var now = new Date();
var distance = end - now;
if (distance < 0 ) {
// handle expiry here..
clearInterval( timer ); // stop the timer from continuing ..
alert('Expired'); // alert a message that the timer has expired..
return; // break out of the function so that we do not update the counters with negative values..
}
var days = Math.floor(distance / _day);
var hours = Math.floor( (distance % _day ) / _hour );
var minutes = Math.floor( (distance % _hour) / _minute );
var seconds = Math.floor( (distance % _minute) / _second );
var milliseconds = Math.floor( (distance % _second) );
document.getElementById('countdown').innerHTML = 'Days: ' + days + '<br />';
document.getElementById('countdown').innerHTML += 'Hours: ' + hours+ '<br />';
document.getElementById('countdown').innerHTML += 'Minutes: ' + minutes+ '<br />';
document.getElementById('countdown').innerHTML += 'Seconds: ' + seconds+ '<br />';
document.getElementById('countdown').innerHTML += 'Milliseconds: ' + milliseconds+ '<br />';
}
timer = setInterval(showRemaining, 1);
最好使用音频插件解决方案。
最好的一个是howler.js。
使用howler.js作为音频插件。然后像这样自定义custom.js
var mySound = new Howl({
urls: ['yoursound.mp3'],
autoplay: true
});
为倒数计时器使用jquery.countdown
然后像这样自定义你的custom.js
$('#clock').countdown('2016/10/31').on('update.countdown',
function(event) {
var $this = $(this).html(event.strftime(''
+ '<div><span>%-w</span>week%!w</div>'
+ '<div><span>%-d</span>day%!d</div>'
+ '<div><span>%H</span>hr</div>'
+ '<div><span>%M</span>min</div>'
+ '<div><span>%S</span>sec</div>'));
});