Last active
January 20, 2019 15:08
-
-
Save melaniemuellerdesign/358f326b9ebe50163916f44c93cd74c1 to your computer and use it in GitHub Desktop.
jQuery fixed header after scroll on wordpress
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
| /*header script*/ | |
| function mobile_header_js() { | |
| ?> | |
| <script> | |
| jQuery(document).ready(function($) { | |
| function fixed() | |
| { | |
| var window_top=$(window).scrollTop(); | |
| var top_position=$('body').offset().top; | |
| var element_to_stick=$('.site-header'); | |
| if (window_top > top_position) { | |
| element_to_stick.addClass('fixed-top'); | |
| } else { | |
| element_to_stick.removeClass('fixed-top'); | |
| } | |
| } | |
| $(window).scroll(sticky); | |
| fixed(); | |
| }); | |
| </script> | |
| <?php } | |
| add_action('wp_head', 'mobile_header_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment