Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nhtua
Created May 16, 2020 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhtua/1b81dad5b065e4406448a0a2cd1e8793 to your computer and use it in GitHub Desktop.
Save nhtua/1b81dad5b065e4406448a0a2cd1e8793 to your computer and use it in GitHub Desktop.
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