OLD | NEW |
1 jQuery(function() | 1 (function(){ |
2 { | 2 |
3 var toTop = jQuery("#to-top"); | 3 function addListener(target, event, callback) |
4 toTop.click(function () | |
5 { | 4 { |
6 jQuery("body,html").animate({ | 5 if (target.addEventListener) |
7 scrollTop: 0 | |
8 }, 800); | |
9 return false; | |
10 }); | |
11 }); | |
12 | |
13 jQuery(window).scroll(function() | |
14 { | |
15 var scrollTop = jQuery(window).scrollTop(); | |
16 | |
17 // Fix header | |
18 var header = jQuery("#header"); | |
19 var height = header.height(); | |
20 var fixed = (scrollTop > height); | |
21 if (fixed != header.hasClass("fixed")) | |
22 { | |
23 if (fixed) | |
24 { | 6 { |
25 header.css("top", -height); | 7 return target.addEventListener(event, callback, false); |
26 header.animate({top: 0},function() | |
27 { | |
28 header.css("top", ""); | |
29 }); | |
30 header.addClass("fixed"); | |
31 } | 8 } |
32 else | 9 else |
33 header.removeClass("fixed"); | 10 { |
| 11 return target.attachEvent("on" + event, callback); |
| 12 } |
34 } | 13 } |
35 | 14 |
36 // Display "to top" button | 15 function onLoad(callback) |
37 var toTop = jQuery("#to-top"); | 16 { |
38 toTop.css("opacity", scrollTop > 100 ? 1 : 0) | 17 if (document.addEventListener) |
39 }); | 18 { |
| 19 return addListener(document, "DOMContentLoaded", callback); |
| 20 } |
| 21 else |
| 22 { |
| 23 return addListener(window, "load", callback); |
| 24 } |
| 25 } |
| 26 |
| 27 onLoad(function() |
| 28 { |
| 29 // expand & contract fixed header |
| 30 |
| 31 var header = document.getElementById("header"); |
| 32 var headerPadding = 13; |
| 33 |
| 34 addListener(window, "scroll", function() |
| 35 { |
| 36 var scrollY = window.scrollY || document.documentElement.scrollTop; |
| 37 |
| 38 if (scrollY < headerPadding) |
| 39 { |
| 40 header.className = "top"; |
| 41 } |
| 42 else |
| 43 { |
| 44 header.className = ""; |
| 45 } |
| 46 }); |
| 47 |
| 48 // open & close header menu (on small screens) |
| 49 |
| 50 var menu = document.getElementById("menu"); |
| 51 var menuButton = document.getElementById("header-hamburger"); |
| 52 |
| 53 addListener(menuButton, "click", function() |
| 54 { |
| 55 if (menu.className === "open") |
| 56 { |
| 57 menu.className = ""; |
| 58 menu.setAttribute("aria-expanded", false); |
| 59 } |
| 60 else |
| 61 { |
| 62 menu.className = "open"; |
| 63 menu.setAttribute("aria-expanded", true); |
| 64 } |
| 65 }); |
| 66 }); |
| 67 |
| 68 }()); |
OLD | NEW |