-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
170 lines (152 loc) · 4.86 KB
/
Copy pathscript.js
File metadata and controls
170 lines (152 loc) · 4.86 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict";
const data = [
{
url: "https://craigsvegan.com/",
gitHubUrl: "https://github.com/RomaneGreen/greensgourmets",
img: "img/craigsvegan.png",
title: "Craig's Vegan",
desc:
"A shopify site built for Craig's Vegan, a vegan ice-cream retailer."
},
{
url: "https://KevinAustinFitness.com/",
gitHubUrl: "https://github.com/RomaneGreen/stream-defy",
img: "img/kevinaustin.png",
title: "Kevin Austin Fitness",
desc:
"Single page Wordpress website built for Kevin Austin, fitness enthusiast and trainer."
},
{
url: "https://www.knewtocrypto.com",
gitHubUrl: "https://github.com/RomaneGreen/knewtocrypto",
img: "img/knewtocrypto.jpg",
title: "New to Crypto?",
desc:
"A website for beginners to cryptocurrency.Built with Ruby on rails,deployed with heroku.CoinMarket API is used to grab data on cryptocurrencies"
},
{
url: "https://getwatchify.com",
gitHubUrl: "https://github.com/RomaneGreen/RomaneGreen.github.io",
img: "img/getwatchify.png",
title: "Get Watchify",
desc:
" A custom watch store built on the shopify platform. "
},
{
url: "https://romanegreen.com/caix.html",
gitHubUrl: "https://github.com/RomaneGreen/RomaneGreen.github.io",
img: "img/caix.png",
title: "CAIX",
desc:
"Custom email newletter for Cryptocurrency Information and Digital Assests Exchange(CAIX)"
}
];
let flexGrid = document.querySelector(".flex-grid");
data.forEach(function(el) {
return (flexGrid.innerHTML +=
'<article class="card">\n<div class="card__thumbnail">\n <a href=' +
el.url +
' target="_blank">\n <img src=' +
el.img +
" alt=" +
el.title +
' class="card__img">\n </a>\n</div>\n<div class="card__description">\n <h3 class="card__heading">\n <a href=' +
el.url +
' target="_blank" class="card__link">' +
el.title +
'</a>\n </h3>\n <p class="card__text">' +
el.desc +
"</p>\n <a href=" +
el.gitHubUrl +
' target="_blank" class="card__github">\n GitHub\n <i class="fab fa-github"></i>\n </a>\n</div>\n</article>');
});
// Browser support
function currentYPosition() {
// Firefox, Chrome, Opera, Safari
if (self.pageYOffset) {
return self.pageYOffset;
}
// Internet Explorer 6 - standards mode
if (document.documentElement && document.documentElement.scrollTop) {
return document.documentElement.scrollTop;
}
// Internet Explorer 6, 7 and 8
if (document.body.scrollTop) {
return document.body.scrollTop;
}
return 0;
}
// Determine the position of the destination element
function elmYPosition(eID) {
let elm = document.querySelector(eID);
let y = elm.offsetTop;
let node = elm;
while (node.offsetParent && node.offsetParent != document.body) {
node = node.offsetParent;
y += node.offsetTop;
}
return y;
}
// Function to do the scrolling
function smoothScroll(eID) {
let startY = currentYPosition();
let stopY = elmYPosition(eID);
let distance = stopY > startY ? stopY - startY : startY - stopY;
if (distance < 100) {
scrollTo(0, stopY);
return;
}
let speed = Math.round(distance / 100);
if (speed >= 20) speed = 20;
let step = Math.round(distance / 25);
let leapY = stopY > startY ? startY + step : startY - step;
let timer = 0;
if (stopY > startY) {
for (let i = startY; i < stopY; i += step) {
setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
leapY += step;
if (leapY > stopY) leapY = stopY;
timer++;
}
return;
}
for (let i = startY; i > stopY; i -= step) {
setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
leapY -= step;
if (leapY < stopY) leapY = stopY;
timer++;
}
return false;
}
// Triggering scroll function
document.querySelector(".user-nav").addEventListener("click", function(event) {
let target = event.target;
let anchorID = target.getAttribute("href");
if (target.nodeName === "I" || target.nodeName === "SPAN") {
anchorID = target.parentElement.getAttribute("href");
}
smoothScroll(anchorID);
});
document
.querySelector(".footer-nav")
.addEventListener("click", function(event) {
let target = event.target;
let anchorID = target.getAttribute("href");
smoothScroll(anchorID);
});
document.querySelector("#cta").addEventListener("click", function() {
smoothScroll("#portfolio");
});
// Submit form
document.querySelector(".form__submit").addEventListener("click", function() {
let formInputs = document.querySelectorAll(".form__input");
for (let i = 0; i < formInputs.length; i++) {
if (formInputs[i].value === "" && formInputs[i].hasAttribute("required")) {
return false;
}
}
document.querySelector(".expand").classList.add("show-expand");
});
document.querySelector(".close-btn").addEventListener("click", function() {
document.querySelector(".expand").classList.remove("show-expand");
});