-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (50 loc) · 1.77 KB
/
index.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
// Simple parallax effect
$('.parallax').each(function() {
var $obj = $(this);
$(window).scroll(function() {
var yPos = -($(window).scrollTop() / $obj.data('speed')),
bgPos = '50% ' + yPos + 'px';
$obj.css('background-position', bgPos);
});
});
// This will get the scroll direction
var currPos = $(window).scrollTop(),
scrollDirection;
$(window).scroll(function() {
var scroll = $(window).scrollTop();
scrollDirection = scroll > currPos ? 'down' : 'up';
currPos = scroll;
});
// This will change classes on scroll
$('.menu ul li a').each(function() {
var link = $(this),
href = $(link.attr('href'));
$(window).scroll(function() {
var h = href.height(),
pos = href.position().top,
scrollPos = $(window).scrollTop();
/*if (scrollDirection === 'down' && scrollPos >= (pos - h/3) && scrollPos < pos && !disableAutomaticScroll) {
$('html, body').animate({scrollTop: pos});
}
if (scrollDirection === 'up' && scrollPos <= (pos + h - h/3) && scrollPos > pos && !disableAutomaticScroll) {
$('html, body').animate({scrollTop: pos});
}*/
if (scrollPos >= (pos - h/3) && scrollPos < (pos + h - h/3)) {
$('.menu ul li a').removeClass('active');
link.addClass('active');
} else {
link.removeClass('active');
}
});
});
// This will disable anchors and scroll to elements basically
var disableAutomaticScroll = false;
$('.menu a[href^="#"]').click(function(e) {
e.preventDefault();
var anchor = $(this).attr('href'),
anchorPos = $(anchor).position().top;
disableAutomaticScroll = true;
$('html, body').animate({scrollTop: anchorPos}, 1000, 'easeInOutBack', setTimeout(function() {
disableAutomaticScroll = false;
}, 700));
});