-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (75 loc) · 2.72 KB
/
Copy pathscript.js
File metadata and controls
90 lines (75 loc) · 2.72 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
function emailIsValid (email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
}
function submitEmail() {
var x, text;
// Get the value of the input field with id="email"
x = document.getElementById("email").value;
if (emailIsValid(x)) {
text = "Email successfully recorded!";
} else {
text = "Invalid email address.";
}
document.getElementById("notice").innerHTML = text;
}
/* with reference to https://codepen.io/danishyma/pen/qBNRQmm */
if(document.getElementById("gallery")){
const lightbox = document.createElement('div')
const images = document.getElementById("gallery").querySelectorAll('img')
lightbox.id = 'lightbox'
document.body.appendChild(lightbox)
images.forEach(image => {
image.addEventListener('click', e => {
lightbox.classList.add('active')
const img = document.createElement('img')
img.src = image.src
while (lightbox.firstChild) {
lightbox.removeChild(lightbox.firstChild)
}
lightbox.appendChild(img)
// This blocks the background from scolling when lightbox is open - must set overflow in main css otherwise on the first time you click on the modal the page will scroll to the top
document.body.style.overflowY='hidden'
})
})
lightbox.addEventListener('click', e => {
if (e.target !== e.currentTarget) return
lightbox.classList.remove('active')
document.body.style.overflowY='scroll'
})
}
/* Video lightbox refers to https://codepen.io/darcyvoutt/pen/MaamWg/ */
// Function to reveal lightbox and adding YouTube autoplay
function revealVideo(div,video_id) {
var video = document.getElementById(video_id).src;
document.getElementById(video_id).src = video+'&autoplay=1'; // adding autoplay to the URL
document.getElementById(div).style.display = 'block';
}
// Hiding the lightbox and removing YouTube autoplay
function hideVideo(div,video_id) {
var video = document.getElementById(video_id).src;
var cleaned = video.replace('&autoplay=1',''); // removing autoplay form url
document.getElementById(video_id).src = cleaned;
document.getElementById(div).style.display = 'none';
}
/* scrollToTop button refer to https://codepen.io/matthewcain/pen/ZepbeR */
var scrollToTopBtn = document.querySelector(".scrollToTopBtn")
function handleScroll() {
// Do something on scroll
var scrollTotal = document.body.scrollHeight - document.body.clientHeight
if (document.body.scrollTop /scrollTotal > 0.25) {
// Show button
scrollToTopBtn.classList.add("show")
} else {
// Hide button
scrollToTopBtn.classList.remove("show")
}
}
function scrollToTop() {
// Scroll to top logic
document.body.scrollTo({
top: 0,
behavior: "smooth"
})
}
document.addEventListener("scroll", handleScroll)
scrollToTopBtn.addEventListener("click", scrollToTop)