문제

I'm looking for a jquery countdown clock or a timer to start with sound play when a date has been setup. I found a lot sites have exapmles of jquery countdown, but no sound play with it when started counting...

how can I add sound to a Jquery countdown timer??

Thanks

Update: this is a demo of mootool timer http://jsfiddle.net/QH6X8/185/ that I want to use a sound play with! any idea how to do that? the html code:

<div id="countdown"></div>

And the mootool code is;

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);
도움이 되었습니까?

해결책

The best bet is to use an audio plugin solution.

One of the best is howler.js.

다른 팁

Use howler.js as audio plugin. Then customize your custom.js like this

var mySound = new Howl({
urls: ['yoursound.mp3'],
autoplay: true
});

For count-down timer use this jquery.countdown

Then customize your custom.js like this

$('#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>'));
 });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top