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

 
(2 intermediate revisions by the same user not shown)
Line 44: Line 44:
 
       if (target.length) {
 
       if (target.length) {
 
         $('html,body').animate({
 
         $('html,body').animate({
           scrollTop: target.offset().top-40
+
           scrollTop: target.offset().top-60
 
         },1000);
 
         },1000);
 
         return false;
 
         return false;
Line 51: Line 51:
 
   });
 
   });
 
});
 
});
 +
$(document).ready(function(){
 +
                    var aChildren = $(".sideBarContent li").children();
 +
                  var aArray = [];
 +
                  for (var i=0; i<aChildren.length; i++){
 +
                        var aChild = aChildren[i];
 +
                      var ahref = $(aChild).attr('href');
 +
                      aArray.push(ahref);
 +
                  }
 +
            $(window).scroll(function(){
 +
                var windowPos2 = $(window).scrollTop();
 +
                var windowHeight = $(window).height();
 +
                var docHeight = $(document).height;
 +
               
 +
                for (var i=0; i < aArray.length; i++){
 +
                    var theID = aArray[i];
 +
                    var divPos = $(theID).offset().top;
 +
                    var divHeight = $(theID).height();
 +
                   
 +
                    if (windowPos2+130 >= divPos && windowPos2+130 < (divPos + divHeight)){
 +
                        $("a[href='" + theID + "']").addClass("sideBarItemActive");
 +
                       
 +
                    }
 +
                    else{
 +
                        $("a[href='" +theID + "']").removeClass("sideBarItemActive");   
 +
                    }
 +
                }
 +
               
 +
                if (windowPos2 + windowHeight == docHeight){
 +
                    if (!$(".sideBarContent li:last-child a").hasClass("sideBarItemActive")){
 +
                    var navActiveCurrent = $(".sideBarItemActive").attr("href");
 +
                        $("a [href='" + navActiveCurrent + "']").removeClass("sideBarItemActive");
 +
                        $(".sideBarContent li:last-child a").addClass("sideBarItemActive");
 +
                       
 +
                    }
 +
                }
 +
                });
 +
    });

Latest revision as of 21:03, 12 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;
     }
   }
 });

}); $(document).ready(function(){

                    var aChildren = $(".sideBarContent li").children();
                  var aArray = [];
                  for (var i=0; i<aChildren.length; i++){
                       var aChild = aChildren[i];
                      var ahref = $(aChild).attr('href');
                      aArray.push(ahref);
                  }
           $(window).scroll(function(){
               var windowPos2 = $(window).scrollTop();
               var windowHeight = $(window).height();
               var docHeight = $(document).height;
               
               for (var i=0; i < aArray.length; i++){
                   var theID = aArray[i];
                   var divPos = $(theID).offset().top;
                   var divHeight = $(theID).height();
                   
                   if (windowPos2+130 >= divPos && windowPos2+130 < (divPos + divHeight)){
                       $("a[href='" + theID + "']").addClass("sideBarItemActive"); 
                       
                   }
                   else{
                       $("a[href='" +theID + "']").removeClass("sideBarItemActive");    
                   }
               } 
               
               if (windowPos2 + windowHeight == docHeight){
                   if (!$(".sideBarContent li:last-child a").hasClass("sideBarItemActive")){
                    var navActiveCurrent = $(".sideBarItemActive").attr("href");
                       $("a [href='" + navActiveCurrent + "']").removeClass("sideBarItemActive");
                       $(".sideBarContent li:last-child a").addClass("sideBarItemActive");
                       
                   }
               }
               });
   });