Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zkreations
Created October 4, 2017 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkreations/c604e9a6cee515a0b6fbb3a98b25a656 to your computer and use it in GitHub Desktop.
Save zkreations/c604e9a6cee515a0b6fbb3a98b25a656 to your computer and use it in GitHub Desktop.
Javascript incluido la data de Blogger para contador regresivo
//<![CDATA[
'use strict';
var getRemainingTime = function getRemainingTime(deadline) {
var now = new Date(),
remainTime = (new Date(deadline) - now + 1000) / 1000,
remainSeconds = ('0' + Math.floor(remainTime % 60)).slice(-2),
remainMinutes = ('0' + Math.floor(remainTime / 60 % 60)).slice(-2),
remainHours = ('0' + Math.floor(remainTime / 3600 % 24)).slice(-2),
remainDays = Math.floor(remainTime / (3600 * 24));
return {
remainSeconds: remainSeconds,
remainMinutes: remainMinutes,
remainHours: remainHours,
remainDays: remainDays,
remainTime: remainTime
};
};
var countdown = function countdown(deadline, elem, finalMessage) {
var el = document.getElementById(elem);
var timerUpdate = setInterval(function () {
var t = getRemainingTime(deadline);
el.innerHTML = '<span class="counter-clock__item">' + t.remainDays + 'd</span><span class="counter-clock__item">' + t.remainHours + 'h</span><span class="counter-clock__item">' + t.remainMinutes + 'm</span><span class="counter-clock__item">' + t.remainSeconds + 's</span>';
if (t.remainTime <= 1) {
clearInterval(timerUpdate);
el.innerHTML = '<p class="counter-clock__info">' + finalMessage + '</p>';
}
}, 1000);
};
//]]>
countdown('<b:eval expr='data:items[1]'/> <b:eval expr='data:items[2]'/>', 'counter-clock', '<b:eval expr='data:items[3]'/>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment