Left: | ||
Right: |
OLD | NEW |
---|---|
1 jQuery(function() | 1 document.addEventListener("DOMContentLoaded", function() |
saroyanm
2016/05/19 07:43:41
addEventListener is not supported in older version
juliandoucette
2016/05/19 12:01:45
My mistake. Will fix.
| |
2 { | 2 { |
3 var toTop = jQuery("#to-top"); | 3 // expand & contract fixed header |
4 toTop.click(function () | 4 |
5 var header = document.getElementById("header"); | |
6 var headerPadding = 13; | |
saroyanm
2016/05/19 07:43:41
Detail: you are using the value only in 1 place so
juliandoucette
2016/05/19 12:01:45
For readability? (To give the literal value meanin
saroyanm
2016/05/23 12:39:20
Acknowledged.
| |
7 | |
8 window.addEventListener("scroll", function() | |
5 { | 9 { |
6 jQuery("body,html").animate({ | 10 var scrollY = window.scrollY || document.documentElement.scrollTop; |
7 scrollTop: 0 | 11 if (scrollY < headerPadding) |
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 { | 12 { |
25 header.css("top", -height); | 13 header.className = "top"; |
26 header.animate({top: 0},function() | |
27 { | |
28 header.css("top", ""); | |
29 }); | |
30 header.addClass("fixed"); | |
31 } | 14 } |
32 else | 15 else |
33 header.removeClass("fixed"); | 16 { |
34 } | 17 header.className = ""; |
18 } | |
19 }, false); | |
35 | 20 |
36 // Display "to top" button | 21 // open & close header menu (on small screens) |
37 var toTop = jQuery("#to-top"); | 22 |
38 toTop.css("opacity", scrollTop > 100 ? 1 : 0) | 23 var menu = document.getElementById("menu"); |
saroyanm
2016/05/19 07:43:40
Detail: you can get the menu element using the "he
juliandoucette
2016/05/19 12:01:45
Yes. But that is a preference.
document.getElemen
saroyanm
2016/05/23 12:39:20
I agree with you
| |
39 }); | 24 var menuButton = document.getElementById("header-hamberger"); |
25 | |
26 menuButton.addEventListener("click", function() | |
27 { | |
28 if (menu.className === "open") | |
29 { | |
30 menu.className = ""; | |
31 menu.setAttribute("aria-expanded", false); | |
32 } | |
33 else | |
34 { | |
35 menu.className = "open"; | |
36 menu.setAttribute("aria-expanded", true); | |
37 } | |
38 }, false); | |
39 }, false); | |
OLD | NEW |