This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 25th, 2013  |  syntax: None  |  size: 1.02 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. /* *******************************************************************************
  3.  
  4.         FLOATING SIDERBARS
  5.  
  6. ********************************************************************************** */  
  7. jQuery(window).load(function(){
  8.         var $window = jQuery(window);
  9.         var $sidebar = jQuery(".sidebar");
  10.         var $footer = jQuery(".footer");
  11.         var $content = jQuery(".content");
  12.         var $WPbar = jQuery("#wpadminbar").length;
  13.         var $addHeigth = 0;
  14.         if ($WPbar>0) $addHeigth = 28;
  15.  
  16.         if($sidebar.length>0){
  17.                 var sidebarTop = $sidebar.position().top;
  18.                 var sidebarHeight = $sidebar.height()+10;
  19.                 var contentHeight = $content.height();
  20.                 var footerTop = $footer.position().top;
  21.  
  22.                
  23.                 if(contentHeight>sidebarHeight){
  24.                         $window.scroll(function(event) {
  25.                                 $sidebar.addClass('fixed');
  26.                                 scrollTop = $window.scrollTop(),
  27.                                 topPosition = Math.max(0, (sidebarTop) - scrollTop),
  28.                                 topPosition = Math.min(topPosition, (footerTop - scrollTop) - sidebarHeight);
  29.                                 $sidebar.css('top', topPosition+$addHeigth);
  30.                         });
  31.                 }
  32.         }
  33. });
clone this paste RAW Paste Data