-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll.js
116 lines (88 loc) · 3.63 KB
/
scroll.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Get a reference to the <path>
var path = document.querySelector('#line-path');
// Get length of path... ~577px in this case
var pathLength = path.getTotalLength();
// Make very long dashes (the length of the path itself)
path.style.strokeDasharray = pathLength +' ' + pathLength;
// Offset the dashes so the it appears hidden entirely
path.style.strokeDashoffset = pathLength;
// Jake Archibald says so
// https://jakearchibald.com/2013/animated-line-drawing-svg/
path.getBoundingClientRect();
// When the page scrolls...
window.addEventListener("scroll", function(e) {
// What % down is it?
// https://stackoverflow.com/questions/2387136/cross-browser-method-to-determine-vertical-scroll-percentage-in-javascript/2387222#2387222
// Had to try three or four differnet methods here. Kind of a cross-browser nightmare.
var scrollPercentage = ((document.documentElement.scrollTop + document.body.scrollTop) / (document.documentElement.scrollHeight - document.documentElement.clientHeight)) - 0.228;
// Length to offset the dashes
var drawLength = pathLength * scrollPercentage * 4.5;
// Draw in reverse
path.style.strokeDashoffset = pathLength - drawLength;
// When complete, remove the dash array, otherwise shape isn't quite sharp
// Accounts for fuzzy math
if (scrollPercentage >= 0.15) {
path.style.strokeDasharray = "none";
} else {
path.style.strokeDasharray = pathLength + ' ' + pathLength;
}
});
window.onscroll = function(){myFunction()};
function myFunction() {
if (document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000)
{
document.getElementById("worktext").className = "appear";
}
if (document.body.scrollTop > 812 || document.documentElement.scrollTop > 812)
{
document.getElementById("a").className = "yearappear";
}
if (document.body.scrollTop > 1009 || document.documentElement.scrollTop > 1009)
{
document.getElementById("b").className = "yearappear";
}
if (document.body.scrollTop > 1105 || document.documentElement.scrollTop > 1105)
{
document.getElementById("c").className = "yearappear";
}
if (document.body.scrollTop > 1230 || document.documentElement.scrollTop > 1230)
{
document.getElementById("d").className = "yearappear";
}
if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500)
{
document.getElementById("introtext").className = "introslideup";
}
if (document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000)
{
document.getElementById("apic").className = "picappear";
}
if (document.body.scrollTop > 1100 || document.documentElement.scrollTop > 1100)
{
document.getElementById("bpic").className = "picappear";
}
if (document.body.scrollTop > 1200 || document.documentElement.scrollTop > 1200)
{
document.getElementById("cpic").className = "picappear";
}
if (document.body.scrollTop > 1250 || document.documentElement.scrollTop > 1250)
{
document.getElementById("dpic").className = "picappear";
}
if (document.body.scrollTop > 1285 || document.documentElement.scrollTop > 1285)
{
document.getElementById("findjob").className = "findjobappear";
}
if (document.body.scrollTop > 1500 || document.documentElement.scrollTop > 1500)
{
document.getElementById("skillstext").className = "skillslideup";
}
if (document.body.scrollTop > 2280 || document.documentElement.scrollTop > 2280)
{
document.getElementById("blogintrotext").className = "blogintroslideup";
}
if (document.body.scrollTop > 2950 || document.documentElement.scrollTop > 2950)
{
document.getElementById("contacttext").className = "contactslideup";
}
}