-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (34 loc) · 1.33 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
import { solutions } from './data-fem.js'
const solutionsEl = document.querySelector('.solutions');
const displaySolutions = (arr) => {
arr.forEach(item => {
const {challenge, folderName, hasJavaScript, usesAPI, solutionUrl} = item;
solutionsEl.innerHTML += `
<div class="solution__card">
<img src="./${folderName}/screenshot-desktop.png" alt="${challenge} solution" class="solution__img" loading="lazy">
<h2 class="solution__challenge">${challenge}</h2>
<ul class="solution__links">
<li><a href="${solutionUrl}">Solution</a></li>
<li><a href="https://helenclx.github.io/Frontend-Mentor-Challenges/${folderName}">Live Site</a></li>
<li><a href="https://github.com/helenclx/Frontend-Mentor-Challenges/tree/main/${folderName}">Repository</a></li>
</ul>
</div>
`;
});
};
displaySolutions(solutions);
const topButton = document.querySelector(".top-btn");
window.onscroll = () => {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
topButton.classList.remove("hidden");
} else {
topButton.classList.add("hidden");
}
}
topButton.addEventListener('click', () => {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
});
});