Last active
October 5, 2018 10:17
-
-
Save luke-rmaki/1149b3d2496f7c34da80b7ee9bd7a368 to your computer and use it in GitHub Desktop.
Revisions
-
Luke revised this gist
Oct 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function elementInView(target) { // selects target div const targetDiv = document.querySelector(target); -
Luke created this gist
Oct 5, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ function smoothScroll(target) { // selects target div const targetDiv = document.querySelector(target); // gets target position from top of viewport const targetPosition = targetDiv.getBoundingClientRect(); switch (true) { case targetPosition.top > 1: console.log('hidden'); break; case targetPosition.top <= 0 && targetPosition.bottom >= 0: console.log('visible'); break; case targetPosition.bottom < 0: console.log('hidden'); break; default: break; } } // add function to document.addEventListener('scroll')