Skip to content

Instantly share code, notes, and snippets.

@WebCulT
Last active May 4, 2019 09:21
Show Gist options
  • Save WebCulT/87ba3bb035f961440b86118116bf925b to your computer and use it in GitHub Desktop.
Save WebCulT/87ba3bb035f961440b86118116bf925b to your computer and use it in GitHub Desktop.
When scroll comes to element something happening
/*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