-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun.js
More file actions
81 lines (69 loc) · 2.33 KB
/
fun.js
File metadata and controls
81 lines (69 loc) · 2.33 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
document.addEventListener('DOMContentLoaded', initSmoothScrolling);
function initSmoothScrolling() {
const menuLinks = document.querySelectorAll('.topmenu');
menuLinks.forEach(link => {
link.addEventListener('click', function(event){
event.preventDefault(); //forhindre forflytning etter default
// hent riktig seksjon fra href
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if(targetElement){
console.log('Scrolling to: ${targetId}');
targetElement.scrollIntoView({
behavior: 'smooth'
});
} else{
console.warn('Element with id ${targetId} not found.');
}
// rull ned til seksjonen med smooth scrolling
});
});
}
// funksjon til hjem-knapp
function scrollToTop(){
window.scrollTo({
top:0,
behavior:'smooth'
});
}
// Meldingsfunksjon
document.getElementById("comms").addEventListener('submit', function(event){
event.preventDefault();
var form = event.target;
var data = new FormData(form);
fetch(form.action, {
method: form.method,
body: data,
headers:{
'Accept': 'application/json'
}
}).then(response => {
if(response.ok) {
form.reset();
document.getElementById('thank-you-message').style.display = 'block';
} else{
response.json().then(data => {
if (data.errors){
alert(data.errors.map(error => error.message).join(", "));
}
});
}
}).catch(error =>{
alert('An error occured when trying to send the message.');
});
});
// prosjekt-objekt smooth transitioning mellom elementene
function toggleDetails(project){
const details = project.querySelector('.project-details');
details.classList.toggle('show');
const detailItems = details.querySelectorAll('.detail-item');
detailItems.forEach((item, index) => {
if(details.classList.contains('show')){
setTimeout(() => {
item.classList.add('show');
}, index*200);
} else{
item.classList.remove('show');
}
});
}