-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
74 lines (64 loc) · 2.34 KB
/
home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function($) {
'use strict';
var $body = $('body'),
$header = $('header'),
$hero = $('.hero'),
$menuTrigger = $('.menu'),
menuHeight = $('.top-bar').height(),
$triggers = $('nav [href^="#"]'),
$scrollItems = $triggers.map(function() {
return $($(this).attr('href'));
}),
lastId;
$(window)
.scroll(function() {
// Handle active menu links
var pageTop = $(this).scrollTop(),
fromTop = pageTop + menuHeight + 50,
mql = window.matchMedia("(max-width:900px)"),
currentElement = $scrollItems.map(function() {
if ($(this).offset().top < fromTop) {
return this;
}
}),
id;
currentElement = currentElement[currentElement.length - 1];
id = currentElement && currentElement.length ? '#' + currentElement[0].id : $triggers.first().attr('href');
if (lastId !== id) {
lastId = id;
$triggers.removeClass('active');
$('[href=' + id + ']').addClass('active');
}
if (mql.matches) {
$header.removeClass('menuHidden');
$body.toggleClass('collapsed', pageTop >= 0);
$hero.toggleClass('sticky', pageTop > 133);
} else {
$header.toggleClass('menuHidden', pageTop < menuHeight);
$body.toggleClass('collapsed', pageTop > menuHeight);
$hero.toggleClass('sticky', pageTop > 333);
}
})
.resize(function() {
$(this).trigger('scroll');
})
.trigger('scroll');
// Manually trigger menu visibility
$menuTrigger.on('click', function() {
$body.toggleClass('collapsed');
});
// Navigation
$('[href^="#"]').on('click', function(e) {
e.preventDefault();
$('html,body').animate({
scrollTop: $($(this).attr('href')).offset().top - menuHeight - 44
}, 250);
});
})(jQuery);
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?2e29c13351c2190707f1a07900a0dc31";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();