Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created October 25, 2019 04:17
Show Gist options
  • Save Risyandi/a124a257e7f77eb92532d523eb384218 to your computer and use it in GitHub Desktop.
Save Risyandi/a124a257e7f77eb92532d523eb384218 to your computer and use it in GitHub Desktop.
a method trigger when scrolling and minimum height of display.
/*
* targetId : is target of element, get based on ID/class/query element.
* htmlBody : count all body HTML.
*/
function triggerScroll() {
let targetId = document.getElementById('topStickyWrapper');
let htmlBody = document.documentElement;
window.addEventListener('scroll', function () {
if (htmlBody.scrollTop > 200 && htmlBody.scrollTop < 1000) {
targetId.classList.add('topStickyFloating');
} else {
targetId.classList.remove('topStickyFloating');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment