Difference between revisions of "Template:Waterloo/JS/header"
(Created page with "// scripts for header // detects scroll for top resizing and lower nav show $(window).scroll(function() { if ($(document).scrollTop() > 50) { $('.main-nav').addClass('s...") |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
if ($(document).scrollTop() > 50) { | if ($(document).scrollTop() > 50) { | ||
$('.main-nav').addClass('shrink'); | $('.main-nav').addClass('shrink'); | ||
− | if ($('#inner-page-links').children().length > 0) { | + | if ($('#inner-page-links').children().length > 0 && window.innerWidth > 768) { |
$('.navbar-lower').removeClass('hide-lower'); | $('.navbar-lower').removeClass('hide-lower'); | ||
} | } | ||
Line 15: | Line 15: | ||
var scrollLinks = {}; | var scrollLinks = {}; | ||
+ | var scroll_top_duration = 700; | ||
+ | var nav_buffer = 24; | ||
// fills in lower nav with inner page links | // fills in lower nav with inner page links | ||
Line 25: | Line 27: | ||
}); | }); | ||
$(".scroll-link").each(function(i, obj) { | $(".scroll-link").each(function(i, obj) { | ||
− | $(obj). | + | $(obj).on('click', function(event){ |
− | + | event.preventDefault(); | |
− | + | var aid = scrollLinks[obj.text]; | |
+ | var aTag = $('#'+aid); | ||
+ | var scroll_location = 0; | ||
+ | if ($(aTag).position().top - nav_buffer > 0){ | ||
+ | scroll_location = $(aTag).position().top - nav_buffer; | ||
+ | } | ||
+ | else { | ||
+ | scroll_location = 0; | ||
+ | } | ||
+ | $('body,html').animate({ | ||
+ | scrollTop: scroll_location, | ||
+ | }, scroll_top_duration | ||
+ | ); | ||
+ | }); | ||
}); | }); | ||
− | if ($('#inner-page-links').children().length < 1) { | + | if ($('#inner-page-links').children().length < 1 || window.innerWidth <= 768) { |
$('.navbar-lower').addClass('hide-lower'); | $('.navbar-lower').addClass('hide-lower'); | ||
} | } | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 19:57, 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 = {}; var scroll_top_duration = 700; var nav_buffer = 24;
// 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();
var aid = scrollLinks[obj.text]; var aTag = $('#'+aid); var scroll_location = 0; if ($(aTag).position().top - nav_buffer > 0){ scroll_location = $(aTag).position().top - nav_buffer; } else { scroll_location = 0; }
$('body,html').animate({ scrollTop: scroll_location, }, scroll_top_duration ); });
}); if ($('#inner-page-links').children().length < 1 || window.innerWidth <= 768) { $('.navbar-lower').addClass('hide-lower'); }
});