Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Farmatique/7ef83fb49188b4fa362fcece90755196 to your computer and use it in GitHub Desktop.
Save Farmatique/7ef83fb49188b4fa362fcece90755196 to your computer and use it in GitHub Desktop.
Call function once when scrolled toa certain position
window.onscroll = myScroll;
var counter = 0; // Global Variable
function myScroll(){
var val = document.getElementById("value");
val.innerHTML = 'pageYOffset = ' + window.pageYOffset;
if(counter == 0){ // if counter is 1, it will not execute
if(window.pageYOffset > 300){
alert('You have scrolled to second div');
counter++; // increment the counter by 1, new value = 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment