Created
April 11, 2013 13:53
-
-
Save verteb/5363561 to your computer and use it in GitHub Desktop.
jQuery sticky element
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
| <style> | |
| #sticky.stick { | |
| position: fixed; | |
| top: 0; | |
| z-index: 99999999999; | |
| } | |
| </style> | |
| <script> | |
| function sticky_relocate() { | |
| var window_top = $(window).scrollTop(); | |
| var div_top = $('#sticky-anchor').offset().top; | |
| if (window_top > div_top) { | |
| $('#sticky').addClass('stick'); | |
| } else { | |
| $('#sticky').removeClass('stick'); | |
| } | |
| } | |
| $(function() { | |
| $(window).scroll(sticky_relocate); | |
| sticky_relocate(); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment