Created
May 16, 2020 04:01
-
-
Save nhtua/1b81dad5b065e4406448a0a2cd1e8793 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 isClicked = false; | |
var btn = document.querySelector('.btn.iso-load-more'); | |
var isInViewport = function (elem) { | |
var bounding = elem.getBoundingClientRect(); | |
return ( | |
bounding.top >= 0 && | |
bounding.left >= 0 && | |
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | |
bounding.right <= (window.innerWidth || document.documentElement.clientWidth) | |
); | |
}; | |
window.onscroll = function(ev) { | |
if (isInViewport(btn) && isClicked==false) { | |
isClicked=true; | |
btn.click(); | |
setTimeout(function(){ | |
isClicked=false; | |
}, 1200); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment