Last active
October 21, 2016 07:58
-
-
Save nash403/283c9b51621c1cbbd736c79e85133d9c to your computer and use it in GitHub Desktop.
How to scroll fix an element
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
// The following code is all pseudo-code | |
let elem = ...; // get element we want to fix | |
let initScrollPosition = ...; // get initial position of element | |
// the following pseudo-code should be is in a scrolling listener | |
if (window.scrollYLevel > initScrollPosition) { | |
elem.css.position = 'fixed'; | |
elem.css.top = 0; // 0 or other position we'd want | |
} else { | |
elem.css.position = 'static'; | |
elem.css.top = 'auto'; // return back to the initial position | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment