-
Notifications
You must be signed in to change notification settings - Fork 1
/
prscript.js
52 lines (42 loc) · 1.54 KB
/
prscript.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
// script.js
// Get all images with class "person"
var images = document.querySelectorAll('.person img');
// Get the modal
var modal = document.getElementById("bioModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// Function to display the modal with the clicked image's alt text
function displayBio(event) {
// Check if the clicked element is not a social icon
if (!event.target.closest('.social-icons')) {
var bioText = event.target.alt;
document.getElementById("bioContent").innerHTML = "<p>" + bioText + "</p>";
modal.style.display = "block";
}
}
// Loop through each image and add a click event listener
images.forEach(function(image) {
image.addEventListener('click', displayBio);
});
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Smooth scroll to anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetElement = document.querySelector(this.getAttribute('href'));
const navbarHeight = document.querySelector('.navbar').offsetHeight;
window.scrollTo({
top: targetElement.offsetTop - navbarHeight,
behavior: 'smooth'
});
});
});