Last active
April 5, 2021 11:17
-
-
Save if0rest/fcba85a3b29b03cfedbf0032f4d768df to your computer and use it in GitHub Desktop.
Бегающие циферки
This file contains hidden or 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
var show = true; | |
var countbox = ".factoid-block"; | |
if ($(countbox).length) { | |
$(window).on("scroll resize", function() { | |
if (!show) return false; | |
var e_top = $(countbox).offset().top; | |
var w_height = $(window).height(); | |
var e_height = $(countbox).outerHeight(); | |
var w_top = $(window).scrollTop(); | |
var d_height = $(document).height(); | |
/* | |
if (e_height + e_top < w_height) | |
delta = 750; | |
else | |
delta = 550; | |
*/ | |
var delta = 1050; | |
var dcf = 2; | |
//if(w_top + delta >= e_top || w_height + w_top == d_height || e_height + e_top < w_height){ | |
if (w_top + delta >= e_top) { | |
$(".factoid-item span.counter").each(function(e, i) { | |
$(this).animateNumber({ | |
number: $(this).text(), | |
numberStep: $.animateNumber.numberStepFactories.separator(' ') | |
}, 1500); | |
}); | |
$(".factoid-item span.decimal").each(function(e, i) { | |
$(this).animateNumber({ | |
number: $(this).text() * dcf, | |
numberStep: function(now, tween) { | |
var floored_number = Math.floor(now) / dcf, | |
target = $(tween.elem); | |
floored_number = floored_number.toFixed(1); | |
// replace '.' separator with ',' | |
floored_number = floored_number.toString().replace('.', ','); | |
target.text(floored_number); | |
} | |
}, 1500); | |
}); | |
show = false; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment