fixed scroll bug mobile mode

master
A1Gard 5 days ago
parent dbf22107dc
commit f0e5354311

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

Loading…
Cancel
Save