LEFT | RIGHT |
1 jQuery(function() | 1 (function(){ |
2 { | 2 function addListener(target, event, callback) |
3 var $toTop = jQuery("#to-top"); | |
4 | |
5 $toTop.click(function () | |
6 { | 3 { |
7 jQuery("body,html").animate({ | 4 if (target.addEventListener) |
8 scrollTop: 0 | 5 return target.addEventListener(event, callback, false); |
9 }, 800); | 6 else |
10 return false; | 7 return target.attachEvent("on" + event, callback); |
| 8 } |
| 9 |
| 10 function onLoad(callback) |
| 11 { |
| 12 if (document.addEventListener) |
| 13 return addListener(document, "DOMContentLoaded", callback); |
| 14 else |
| 15 return addListener(window, "load", callback); |
| 16 } |
| 17 |
| 18 onLoad(function() |
| 19 { |
| 20 // expand & contract fixed header |
| 21 var header = document.getElementById("header"); |
| 22 var headerPadding = 13; |
| 23 addListener(window, "scroll", function() |
| 24 { |
| 25 var scrollY = window.scrollY || document.documentElement.scrollTop; |
| 26 if (scrollY < headerPadding) |
| 27 header.className = "top"; |
| 28 else |
| 29 header.className = ""; |
| 30 }); |
| 31 // open & close header menu (on small screens) |
| 32 var menu = document.getElementById("menu"); |
| 33 var menuButton = document.getElementById("header-hamburger"); |
| 34 addListener(menuButton, "click", function() |
| 35 { |
| 36 if (menu.className === "open") |
| 37 { |
| 38 menu.className = ""; |
| 39 menu.setAttribute("aria-expanded", false); |
| 40 } |
| 41 else |
| 42 { |
| 43 menu.className = "open"; |
| 44 menu.setAttribute("aria-expanded", true); |
| 45 } |
| 46 }); |
11 }); | 47 }); |
12 | 48 }()); |
13 var $window = jQuery(window); | |
14 var $header = jQuery("#header"); | |
15 var headerPadding = 13; | |
16 | |
17 $window.scroll(function() | |
18 { | |
19 if ($window.scrollTop() > headerPadding) | |
20 { | |
21 if ($header.hasClass("top")) | |
22 { | |
23 $header.removeClass("top"); | |
24 $toTop.show(); | |
25 } | |
26 } | |
27 else | |
28 { | |
29 if (!$header.hasClass("top")) | |
30 { | |
31 $header.addClass("top"); | |
32 $toTop.hide(); | |
33 } | |
34 } | |
35 }); | |
36 | |
37 jQuery('#header-hamberger').click(function() | |
38 { | |
39 var $menu = jQuery("#menu"); | |
40 | |
41 if ($menu.hasClass("open")) { | |
42 $menu.removeClass("open"); | |
43 $menu.attr("aria-expanded", false); | |
44 } | |
45 else | |
46 { | |
47 $menu.addClass("open"); | |
48 $menu.attr("aria-expanded", true); | |
49 } | |
50 }) | |
51 | |
52 }); | |
LEFT | RIGHT |