Last active
May 4, 2019 09:21
-
-
Save WebCulT/87ba3bb035f961440b86118116bf925b to your computer and use it in GitHub Desktop.
When scroll comes to element something happening
This file contains 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
/*TEMPLATE CODE FOR SCROLL WINDOW TILL CONCRETE ELEMENT*/ | |
function scrollElement(event, arr, funcBottom, funcTop) { | |
for(var i = 0; i < arr[0].length; i++) { //Zero elememt of array is the main collaction of our func. | |
var cordsSkill = arr[0][i].getBoundingClientRect().top, | |
num = parseFloat(arr[0][i].textContent), | |
cordsScroll = window.pageYOffset + document.documentElement.clientHeight; | |
if(cordsScroll >= cordsSkill + window.pageYOffset) { | |
funcBottom(i, num); | |
} | |
if(cordsScroll <= cordsSkill + window.pageYOffset) { | |
funcTop(i, num); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment