-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (31 loc) · 1.24 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
//this is where we apply opacity to the arrow
$(window).scroll( function(){
//get scroll position
var topWindow = $(window).scrollTop();
//multipl by 1.5 so the arrow will become transparent half-way up the page
var topWindow = topWindow * 1.5;
//get height of window
var windowHeight = $(window).height();
//set position as percentage of how far the user has scrolled
var position = topWindow / windowHeight;
//invert the percentage
position = 1 - position;
//define arrow opacity as based on how far up the page the user has scrolled
//no scrolling = 1, half-way up the page = 0
$('.arrow-wrap').css('opacity', position);
});
//Code stolen from css-tricks for smooth scrolling:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});