Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- 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(), before.getMonth(), 32);
- days += 32 - date.getDate();
- months--;
- }
- if (months < 0)
- {
- months += 12;
- years--;
- }
- return {
- years: years,
- months: months,
- days: days,
- hours: hours,
- minutes: minutes,
- seconds: seconds
- };
- },
- process: function(before, after)
- {
- var diff = null, a = [], i = '';
- if(!(diff = Countdown.difference(before, after))) return false;
- for(i in diff)
- {
- if(!diff[i]) continue;
- a.push('<span class="num">'
- + diff[i] +
- '</span><span class="unit">'
- + Countdown.lang[i][Countdown.lang.choose( diff[i] )] +
- '</span>');
- }
- return a.join(' ');
- },
- lang:
- {
- years: ['год', 'года', 'лет'],
- months: ['месяц', 'месяца', 'месяцев'],
- days: ['день', 'дня', 'дней'],
- hours: ['час', 'часа', 'часов'],
- minutes: ['минута', 'минуты', 'минут'],
- seconds: ['секунда', 'секунды', 'секунд'],
- choose: function(n)
- {
- var m = n % 100, i = 2;
- if(m < 5 || 20 < m)
- {
- if((m %= 10) === 1)
- {
- i = 0;
- }
- else if(1 < m && m < 5)
- {
- i = 1;
- }
- }
- return i;
- }
- }
- };
- window.onload = function()
- {
- Countdown.init('countbox', new Date(2010, 10, 29, 1, 1, 00));
- };
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement