SHARE
TWEET

mesocolumn main nav scroll fixed

a guest Jan 28th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function meso_float_primary_fixed() { ?>
  2. <?php
  3. if( is_user_logged_in() ) { $log = 'true'; } else { $log = 'false'; }
  4. if( is_admin_bar_showing() ) { $abshow = 'true'; } else { $abshow = 'false'; } ?>
  5. <script type="text/javascript">
  6. jQuery.noConflict();
  7. var $st = jQuery;
  8. var log = <?php echo $log; ?>;
  9. var abs = <?php echo $abshow; ?>;
  10. $st(document).ready(function() {
  11.  
  12.     // grab the initial top offset of the navigation
  13.     var sticky_navigation_offset_top = $st('#main-navigation').offset().top;
  14.  
  15.     // our function that decides weather the navigation bar should have "fixed" css position or not.
  16.     var sticky_navigation = function(){
  17.         var scroll_top = $st(window).scrollTop(); // our current vertical position from the top
  18.  
  19.  
  20.         // if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
  21.         if (scroll_top > sticky_navigation_offset_top) {
  22.         if( log == true ) {
  23.         if( abs == true ) {
  24.         $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff', 'z-index': '9999','position': 'fixed', 'padding': '0','top':30, 'left':0 });
  25.         } else {
  26.          $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff', 'z-index': '9999','position': 'fixed', 'padding': '0','top':0, 'left':0 });
  27.         }
  28.  
  29.         } else {
  30.         $st('#main-navigation').css({ 'box-shadow': '0 0 10px #333','background-color': '#fff','z-index': '9999','position': 'fixed','top':0, 'left':0 });
  31.         }
  32.  
  33.         } else {
  34.             $st('#main-navigation').css({ 'box-shadow': 'none','position': 'relative','padding': '0' });
  35.         }
  36.  
  37.     };
  38.  
  39.     // run our function on load
  40.     sticky_navigation();
  41.  
  42.     // and run it again every time you scroll
  43.     $st(window).scroll(function() {
  44.          sticky_navigation();
  45.     });
  46.  
  47.     // NOT required:
  48.     // for this demo disable all links that point to "#"
  49.     $st('a[href="#"]').click(function(event){
  50.         event.preventDefault();
  51.     });
  52.  
  53. });
  54. </script>
  55. <?php }
  56. add_action('wp_head','meso_float_primary_fixed',10);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top