Last active
March 19, 2024 05:55
-
-
Save Rupashdas/80e7a98d675af1fc3201720c2bef6e6b to your computer and use it in GitHub Desktop.
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 countDown(selector) { | |
var countDownElement = $(selector); | |
var startAt = parseFloat(countDownElement.attr('start-at')); | |
var endAt = parseFloat(countDownElement.attr('end-at')); | |
var animationDuration = parseFloat(countDownElement.attr('animation-duration').replace('ms', '')); | |
var currentValue = startAt; | |
var interval = 50; | |
var steps = (startAt - endAt) / (animationDuration / interval); | |
var timer = setInterval(function () { | |
currentValue -= steps; | |
countDownElement.text(currentValue.toFixed(2)); | |
if (currentValue <= endAt) { | |
clearInterval(timer); | |
countDownElement.text(endAt.toFixed(2)); | |
} | |
}, interval); | |
} | |
let countDownSelectors = ".count-down"; | |
if ($(countDownSelectors).length > 0) { | |
$(countDownSelectors).each(function (index, item) { | |
var waypoint = new Waypoint({ | |
element: $(this), | |
handler: function () { | |
countDown(item); | |
this.destroy(); | |
}, | |
offset: 'bottom-in-view', | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment