-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
85 lines (69 loc) · 2.93 KB
/
script.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
document.addEventListener('DOMContentLoaded', function() {
const darkModeToggle = document.getElementById('darkmode-switch');
const body = document.body;
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
function setDarkMode(isDark) {
if (isDark) {
body.classList.add('dark-mode');
darkModeToggle.checked = true;
} else {
body.classList.remove('dark-mode');
darkModeToggle.checked = false;
}
}
if (localStorage.getItem('darkMode') === 'enabled') {
setDarkMode(true);
} else if (localStorage.getItem('darkMode') === 'disabled') {
setDarkMode(false);
} else {
setDarkMode(prefersDarkScheme.matches);
}
darkModeToggle.addEventListener('change', function() {
setDarkMode(this.checked);
localStorage.setItem('darkMode', this.checked ? 'enabled' : 'disabled');
});
prefersDarkScheme.addListener((e) => {
if (localStorage.getItem('darkMode') === null) {
setDarkMode(e.matches);
}
});
// FAQ-funktionalitet
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('h3');
const answer = item.querySelector('p');
const icon = item.querySelector('i');
question.addEventListener('click', () => {
const isOpen = answer.style.display === 'block';
answer.style.display = isOpen ? 'none' : 'block';
// Rotera ikonen, ändra bakgrundsfärg och ikonens färg
icon.style.transform = isOpen ? 'rotate(0deg)' : 'rotate(180deg)';
icon.style.backgroundColor = isOpen ? '' : '#6366F1';
icon.style.color = isOpen ? '' : '#FFFFFF'; // Ändra ikonens färg när den är aktiv
icon.style.borderRadius = isOpen ? '' : '50%';
// Stäng andra öppna FAQ-objekt
faqItems.forEach(otherItem => {
if (otherItem !== item) {
const otherAnswer = otherItem.querySelector('p');
const otherIcon = otherItem.querySelector('i');
otherAnswer.style.display = 'none';
otherIcon.style.transform = 'rotate(0deg)';
otherIcon.style.backgroundColor = '';
otherIcon.style.color = '';
otherIcon.style.borderRadius = '';
}
});
});
});
});
document.addEventListener('DOMContentLoaded', function() {
const img = document.querySelector('.rotate-on-hover');
img.addEventListener('mouseenter', function() {
this.style.transition = 'transform 0.5s ease';
this.style.transform = 'rotate(360deg)';
});
img.addEventListener('mouseleave', function() {
this.style.transition = 'transform 0.5s ease';
this.style.transform = 'rotate(0deg)';
});
});