|
|
|
@ -6,13 +6,15 @@ var isCounterInited = false;
|
|
|
|
|
function isElementInViewport(el) {
|
|
|
|
|
const rect = el.getBoundingClientRect();
|
|
|
|
|
return (
|
|
|
|
|
rect.top >= 0 &&
|
|
|
|
|
rect.left >= 0 &&
|
|
|
|
|
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
|
|
|
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
|
|
|
rect.bottom > 0 &&
|
|
|
|
|
rect.right > 0 &&
|
|
|
|
|
rect.top < (window.innerHeight || document.documentElement.clientHeight) &&
|
|
|
|
|
rect.left < (window.innerWidth || document.documentElement.clientWidth)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function uncommafy(txt) {
|
|
|
|
|
return txt.split(',').join('');
|
|
|
|
|
}
|
|
|
|
@ -31,10 +33,10 @@ function commafy(num) {
|
|
|
|
|
return str.join('.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
|
|
|
|
|
window.addEventListener('scroll', function() {
|
|
|
|
|
const handleScroll = function() {
|
|
|
|
|
const container = document.getElementById('CounterGrid');
|
|
|
|
|
console.log(isElementInViewport(container));
|
|
|
|
|
if (container == null){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
@ -66,7 +68,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
// Remove event listener if you only want to alert once
|
|
|
|
|
// this.removeEventListener('scroll', arguments.callee);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
|
|
|
|
|
window.addEventListener('scroll', handleScroll);
|
|
|
|
|
window.addEventListener('touchmove', handleScroll);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|