Difference between revisions of "Template:Waterloo/JS/header.js"
Line 25: | Line 25: | ||
$("#inner-page-links").append('<li><a href="#" class="scroll-link">'+obj.id.capitalize()+'</a></li>'); | $("#inner-page-links").append('<li><a href="#" class="scroll-link">'+obj.id.capitalize()+'</a></li>'); | ||
}); | }); | ||
− | $(".scroll-link").each(function(i, obj) { | + | // $(".scroll-link").each(function(i, obj) { |
− | + | // $(obj).click(function() { | |
− | + | // scrollToAnchor(obj.content); | |
− | + | // }); | |
− | }); | + | // }); |
if ($('#inner-page-links').children().length < 1) { | if ($('#inner-page-links').children().length < 1) { | ||
$('.navbar-lower').addClass('hide-lower') | $('.navbar-lower').addClass('hide-lower') | ||
Line 35: | Line 35: | ||
}); | }); | ||
− | + | $('li.scroll-link').delegate('a','click',function(obj) { | |
− | + | scrollToAnchor(obj.content); | |
− | + | }); | |
// for smooth scrolling | // for smooth scrolling |
Revision as of 22:21, 21 August 2015
// scripts for header
// for capitalizing id String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
// 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') }
});
// fills in lower nav with inner page links $(document).ready(function(){
$('.accordion-heading').addClass('link'); $('.link').each(function(i, obj) {$("#inner-page-links").append('
}); // $(".scroll-link").each(function(i, obj) { // $(obj).click(function() { // scrollToAnchor(obj.content); // }); // }); if ($('#inner-page-links').children().length < 1) { $('.navbar-lower').addClass('hide-lower') }
});
$('li.scroll-link').delegate('a','click',function(obj) {
scrollToAnchor(obj.content);
});
// for smooth scrolling function scrollToAnchor(aid){
var aTag = $('#'+aid); if(aTag.length){ $('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); }
}