Опубликовал admin в разделе
javascript on 10 28th, 2008 |
3 Comments
JavaScript cчётчик обратного отсчёта (время до события)...
var Countdown =
{
timer: null,
init: function(id, until)
{
Countdown.node = document.getElementById(id);
Countdown.update(until);
Countdown.timer = setInterval(function()
{
Countdown.update(until);
}, 1000);
},
stop: function()
{
clearInterval(Countdown.timer);
return true;
},
update: function(until)
{
var s = Countdown.process(new Date(), until);
Countdown.node.innerHTML = s || Countdown.stop() && 'Всё ';
},
difference: function(before, after)
{
if (after < before) return false;
var
days = after.getDate() - before.getDate(),
months = after.getMonth() - before.getMonth(),
years = after.getYear() - before.getYear(),
hms = (after / 1000 - before / 1000) % 86400,
seconds = Math.floor(hms % 60),
minutes = Math.floor(hms/60) % 60,
hours = Math.floor(hms/3600) % 60,
date = new Date();
if (days < 0)
{
date.setFullYear(before.getYear(),...