Advertisement
Guest User

Fixed Header

a guest
Feb 21st, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. // =========================================
  2. // = Fixed Header =
  3. // =========================================
  4.  
  5. add_action('wp_enqueue_scripts', 'add_my_code');
  6.  
  7. function add_my_code() {
  8.     add_action( 'print_footer_scripts', 'my_footer_script' );
  9. }
  10.  
  11.  
  12. function my_footer_script() { ?>
  13.  
  14.   <script type="text/javascript">
  15.  
  16.     jQuery(function($) {
  17.  
  18.         var $filter = $('#header');
  19.         var $filterSpacer = $('<div />', {
  20.             "class": "filter-drop-spacer",
  21.             "height": $filter.outerHeight()
  22.         });
  23.  
  24.  
  25.         if ($filter.size())
  26.         {
  27.             $(window).scroll(function ()
  28.             {
  29.                 if (!$filter.hasClass('fix') && $(window).scrollTop() > $filter.offset().top)
  30.                 {
  31.                     $filter.before($filterSpacer);
  32.                     $filter.addClass("fix");
  33.                 }
  34.                 else if ($filter.hasClass('fix')  && $(window).scrollTop() < $filterSpacer.offset().top)
  35.                 {
  36.                     $filter.removeClass("fix");
  37.                     $filterSpacer.remove();
  38.                 }
  39.             });
  40.         }
  41.  
  42.     });
  43.  
  44.   </script>
  45.  
  46. <?php }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement