Difference between revisions of "Template:Waterloo/JS/header.js"

(Created page with "// scripts for header // detects scroll for top resizing and lower nav show $(window).scroll(function() { if ($(document).scrollTop() > 50) { $('.navbar-fixed-top').addCla...")
 
Line 5: Line 5:
 
   if ($(document).scrollTop() > 50) {
 
   if ($(document).scrollTop() > 50) {
 
     $('.navbar-fixed-top').addClass('shrink');
 
     $('.navbar-fixed-top').addClass('shrink');
     $('.navbar-lower').removeClass('hide-lower')
+
     if ($('#inner-page-links').children().length > 0) {
 +
      $('.navbar-lower').removeClass('hide-lower')
 +
    }
 
   } else {
 
   } else {
 
     $('.navbar-fixed-top').removeClass('shrink');
 
     $('.navbar-fixed-top').removeClass('shrink');
Line 19: Line 21:
 
// fills in lower nav with inner page links
 
// fills in lower nav with inner page links
 
$(document).ready(function(){
 
$(document).ready(function(){
$('.link').each(function(i, obj) {
+
  $('.link').each(function(i, obj) {
    $("#inner-page-links").append('<li><a href="#'+obj.id+'">'+obj.id+'</a></li>');
+
    $("#inner-page-links").append('<li><a href="#'+obj.id+'">'+obj.id+'</a></li>');
});});
+
  });
 +
  if ($('#inner-page-links').children().length < 1) {
 +
    $('.navbar-lower').addClass('hide-lower')
 +
  }
 +
});
  
 
// for smooth scrolling
 
// for smooth scrolling

Revision as of 17:56, 21 August 2015

// scripts for header

// detects scroll for top resizing and lower nav show $(window).scroll(function() {

 if ($(document).scrollTop() > 50) {
   $('.navbar-fixed-top').addClass('shrink');
   if ($('#inner-page-links').children().length > 0) {
     $('.navbar-lower').removeClass('hide-lower')
   }
 } else {
   $('.navbar-fixed-top').removeClass('shrink');
   $('.navbar-lower').addClass('hide-lower')
 }

});

// set lower navbar $('.navbar-lower').affix({

 offset: {top: 200}

});

// fills in lower nav with inner page links $(document).ready(function(){

 $('.link').each(function(i, obj) {
$("#inner-page-links").append('
  • <a href="#'+obj.id+'">'+obj.id+'</a>
  • ');
     });
     if ($('#inner-page-links').children().length < 1) {
       $('.navbar-lower').addClass('hide-lower')
     }
    

    });

    // for smooth scrolling $(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
           }, 500);
           return false;
         }
       }
     });
    

    });