Created
June 14, 2018 10:35
-
-
Save Farmatique/7ef83fb49188b4fa362fcece90755196 to your computer and use it in GitHub Desktop.
Call function once when scrolled toa certain position
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
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