Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 2.33 KB  |  hits: 12  |  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. jQuery(document).ready(function($){
  2.        
  3.         //vars
  4.         var pagePanels = [],
  5.                 panelsId = [],
  6.                 panelsOffset = [];
  7.  
  8.     // Stores the links to the panels
  9.         $('#navigation div > div.navMenuLeft a, #navigation div > div.navMenuRight a')
  10.                 .each( function(i) {
  11.                         pagePanels[i] = $(this);
  12.                 });
  13.    
  14.     // Stores the panel anchores
  15.         $(pagePanels)
  16.                 .each( function(i) {
  17.                         panelsId[i] = $(this).attr('href');
  18.                 });
  19.  
  20.     // Stores the offset of each panel
  21.     $(panelsId)
  22.         .each( function(i) {
  23.             panelsOffset[i] = returnOffset($(panelsId[i]));
  24.         });
  25.        
  26.         // Returns Document Position
  27.         function returnDocumentScoll() {
  28.                 var docPos = $(document).scrollTop();
  29.                 return docPos;
  30.         }
  31.    
  32.     // Returns the offset of onobject
  33.         function returnOffset(obj) {
  34.         var objectOffset = $(obj).offset();
  35.         return objectOffset.top;      
  36.  
  37.         }
  38.        
  39.         // Finds the active anchor in the navigation
  40.         function findActiveAnchor() {
  41.            
  42.             var docOffset = returnDocumentScoll(),
  43.                 i = docOffset;
  44.  
  45.         $('.navMenuWrap .active')
  46.             .removeClass('active');
  47.        
  48.         if(i < panelsOffset[1]) {
  49.             $(pagePanels[0])
  50.                 .addClass('active');
  51.         } else if(i < panelsOffset[2] && i >= panelsOffset[1]) {
  52.              $(pagePanels[1])
  53.                     .addClass('active');
  54.         } else if(i < panelsOffset[3] && i >= panelsOffset[2] - 1) {
  55.             $(pagePanels[2])
  56.                 .addClass('active');
  57.         } else {
  58.             $(pagePanels[3])
  59.                 .addClass('active');
  60.         }
  61.         }
  62.        
  63.         // If there isn't enough height for the donate navigation to transition this fixes the issue
  64.         var footerHeight = $('#footer').height();
  65.          
  66.         function setFooterHeight() {
  67.             if($('#donateWrap').height() < $(window).height()) {
  68.                
  69.                 var remainder = $(window).height() - $('#donateWrap').height();
  70.                    
  71.                 $('#footer')
  72.                     .css({
  73.                         'height': footerHeight + remainder
  74.                     });
  75.             } else {
  76.                 $('#footer')
  77.                     .css({
  78.                         'height': footerHeight
  79.                     });
  80.             }
  81.         }
  82.        
  83.         $(window)
  84.         .load( function(){
  85.                         findActiveAnchor();
  86.                         setFooterHeight();
  87.                         $(pagePanels[0])
  88.                 .addClass('active');
  89.                 })
  90.                 .resize( function() {
  91.             setFooterHeight();
  92.                 })
  93.                 .scroll( function(){
  94.             findActiveAnchor();
  95.                 });
  96. });