Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function meso_float_primary_fixed() { ?>
- <?php
- if( is_user_logged_in() ) { $log = 'true'; } else { $log = 'false'; }
- if( is_admin_bar_showing() ) { $abshow = 'true'; } else { $abshow = 'false'; } ?>
- <script type="text/javascript">
- jQuery.noConflict();
- var $st = jQuery;
- var log = <?php echo $log; ?>;
- var abs = <?php echo $abshow; ?>;
- $st(document).ready(function() {
- // grab the initial top offset of the navigation
- var sticky_navigation_offset_top = $st('#main-navigation').offset().top;
- // our function that decides weather the navigation bar should have "fixed" css position or not.
- var sticky_navigation = function(){
- var scroll_top = $st(window).scrollTop(); // our current vertical position from the top
- // if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
- if (scroll_top > sticky_navigation_offset_top) {
- if( log == true ) {
- if( abs == true ) {
- $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff', 'z-index': '9999','position': 'fixed', 'padding': '0','top':30, 'left':0 });
- } else {
- $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff', 'z-index': '9999','position': 'fixed', 'padding': '0','top':0, 'left':0 });
- }
- } else {
- $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff','z-index': '9999','position': 'fixed','top':0, 'left':0 });
- }
- } else {
- $st('#main-navigation').css({ 'box-shadow': 'none','position': 'relative','padding': '0' });
- }
- };
- // run our function on load
- sticky_navigation();
- // and run it again every time you scroll
- $st(window).scroll(function() {
- sticky_navigation();
- });
- // NOT required:
- // for this demo disable all links that point to "#"
- $st('a[href="#"]').click(function(event){
- event.preventDefault();
- });
- });
- </script>
- <?php }
- add_action('wp_head','meso_float_primary_fixed',10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement