Last active
August 5, 2019 11:11
-
-
Save nikhilatjumpcut/4f15a02c2b0e4bd3b35907ec051792f7 to your computer and use it in GitHub Desktop.
enroll_countdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function startCountdown() { | |
var funnelAccess = window.__TSUNAMI__.funnelAccess; | |
var currentStep = funnelAccess.find(function(access) { | |
if (access.isCurrentStep) { | |
return true; | |
} | |
return false; | |
}); | |
var closingDate = currentStep.expiryTimestamp; | |
if (!closingDate) { | |
document.getElementById('countdown-container').style.display = 'none'; | |
return; | |
} | |
document.getElementById('countdown-container').style.display = 'block'; | |
var countDownDate = new Date(closingDate).getTime(); | |
var x = setInterval(function() { | |
var now = new Date().getTime(); | |
var distance = countDownDate - now; | |
var days = Math.floor(distance / (1000 * 60 * 60 * 24)); | |
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | |
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); | |
var seconds = Math.floor((distance % (1000 * 60)) / 1000); | |
document.getElementById('days').innerText = days; | |
document.getElementById('hours').innerText = hours; | |
document.getElementById('minutes').innerText = minutes; | |
document.getElementById('seconds').innerText = seconds; | |
if (distance < 0) { | |
clearInterval(x); | |
document.getElementById('countdown-container').style.display = 'none'; | |
} | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment