Difference between revisions of "Team:Lethbridge HS/pageControlScripts"

Line 44: Line 44:
 
       if (target.length) {
 
       if (target.length) {
 
         $('html,body').animate({
 
         $('html,body').animate({
           scrollTop: target.offset().top-20
+
           scrollTop: target.offset().top-60
 
         },1000);
 
         },1000);
 
         return false;
 
         return false;

Revision as of 01:08, 10 September 2015

jQuery(document).ready(function(){

                    var aChildren = jQuery(".sideBarContent li").children();
                  var aArray = [];
                  for (var i=0; i<aChildren.length; i++){
                       var aChild = aChildren[i];
                      var ahref = jQuery(aChild).attr('href');
                      aArray.push(ahref);
                  }
           jQuery(window).scroll(function(){
               var windowPos2 = jQuery(window).scrollTop();
               var windowHeight = jQuery(window).height();
               var docHeight = jQuery(document).height;
               
               for (var i=0; i < aArray.length; i++){
                   var theID = aArray[i];
                   var divPos = jQuery(theID).offset().top;
                   var divHeight = jQuery(theID).height();
                   
                 if (windowPos2+130 >= divPos && windowPos2+130 < (divPos + divHeight)){
                       jQuery("a[href='" + theID + "']").addClass("sideBarItemActive"); 
                       
                   }
                   else{
                       jQuery("a[href='" +theID + "']").removeClass("sideBarItemActive");    
                   }
               } 
               
               if (windowPos2 + windowHeight == docHeight){
                   if (!jQuery(".sideBarContent li:last-child a").hasClass("sideBarItemActive")){
                    var navActiveCurrent = jQuery(".sideBarItemActive").attr("href");
                       jQuery("a [href='" + navActiveCurrent + "']").removeClass("sideBarItemActive");
                       jQuery(".sideBarContent li:last-child a").addClass("sideBarItemActive");
                       
                   }
               }
               });
   });
       $(function() {
 $('a[href*=#]:not([href=#])').click(function() {
   if (location.pathname.replace(/^\//,) == this.pathname.replace(/^\//,) && location.hostname == this.hostname) {
     var target = $(this.hash);
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
     if (target.length) {
       $('html,body').animate({
         scrollTop: target.offset().top-60
       },1000);
       return false;
     }
   }
 });

});