Difference between revisions of "Template:Waterloo/JS/header"
m (Removing console.log) |
|||
Line 25: | Line 25: | ||
}); | }); | ||
$(".scroll-link").each(function(i, obj) { | $(".scroll-link").each(function(i, obj) { | ||
− | $ | + | $obj.on('click', function(event){ |
− | + | event.preventDefault(); | |
− | + | $('body,html').animate({ | |
+ | var aid = scrollLinks[obj.text]; | ||
+ | var aTag = $('#'+aid); | ||
+ | scrollTop: $(aTag).position().top, | ||
+ | }, scroll_top_duration | ||
+ | ); | ||
+ | }); | ||
}); | }); | ||
if ($('#inner-page-links').children().length < 1 || window.innerWidth <= 768) { | if ($('#inner-page-links').children().length < 1 || window.innerWidth <= 768) { |
Revision as of 19:42, 17 September 2015
// scripts for header
// detects scroll for top resizing and lower nav show $(window).scroll(function() {
if ($(document).scrollTop() > 50) { $('.main-nav').addClass('shrink'); if ($('#inner-page-links').children().length > 0 && window.innerWidth > 768) { $('.navbar-lower').removeClass('hide-lower'); } } else { $('.main-nav').removeClass('shrink'); $('.navbar-lower').addClass('hide-lower'); }
});
var scrollLinks = {};
// fills in lower nav with inner page links $(document).ready(function(){
$('.accordion-heading').addClass('link'); $('section').addClass('link'); $('.link').each(function(i, obj) {$("#inner-page-links").append('
scrollLinks[obj.title] = obj.id; }); $(".scroll-link").each(function(i, obj) { $obj.on('click', function(event){
event.preventDefault(); $('body,html').animate({
var aid = scrollLinks[obj.text]; var aTag = $('#'+aid);
scrollTop: $(aTag).position().top, }, scroll_top_duration ); });
}); if ($('#inner-page-links').children().length < 1 || window.innerWidth <= 768) { $('.navbar-lower').addClass('hide-lower'); }
});
// for smooth scrolling function scrollToAnchor(aid){
var aTag = $('#'+aid); if(aTag.length){ $('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); }
}