ETFs como uma ferramenta importante na diversificação dos portfólios
';
}
});
this.container.innerHTML = html;
}
update() {
const now = new Date().getTime();
const distanceToStart = this.targetDate.getTime() - now;
const distanceToEnd = this.endDate.getTime() - now;
// Se passou do fim do evento
if (distanceToEnd 0) {
this.happening();
return;
}
// Countdown normal antes do evento
const values = {
days: Math.floor(distanceToStart / (1000 * 60 * 60 * 24)),
hours: Math.floor((distanceToStart % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
minutes: Math.floor((distanceToStart % (1000 * 60 * 60)) / (1000 * 60))
};
Object.keys(values).forEach(unit => {
const element = this.container.querySelector(`[data-unit="${unit}"]`);
if (element) {
const newValue = this.padZero(values[unit]);
if (this.isInitialized && this.previousValues[unit] !== newValue) {
this.animateChange(element, newValue);
} else {
element.textContent = newValue;
}
this.previousValues[unit] = newValue;
}
});
}
animateChange(element, newValue) {
element.classList.add('flip', 'flash');
setTimeout(() => {
element.textContent = newValue;
}, 300);
setTimeout(() => {
element.classList.remove('flip', 'flash');
}, 600);
}
padZero(num) {
return num.toString().padStart(2, '0');
}
happening() {
if(this.intervalId) clearInterval(this.intervalId);
// Esconde o título
const title = document.querySelector('.countdown-title');
if(title) title.style.display = 'none';
this.container.innerHTML = `
${this.config.happeningTitle}
`;
// Continua verificando se o evento terminou
this.intervalId = setInterval(() => {
const now = new Date().getTime();
const distanceToEnd = this.endDate.getTime() - now;
if (distanceToEnd
${this.config.finishedTitle}
`;
}
}
(function() {
function init() {
try {
new AvelCountdown(COUNTDOWN_CONFIG);
} catch(e) {
console.error('Countdown error:', e);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();