-
Notifications
You must be signed in to change notification settings - Fork 0
/
destination.js
71 lines (56 loc) · 2.34 KB
/
destination.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
import user from "./data.json" assert { type: 'json' };
const navButton = document.querySelector('.mobile-nav-toggle');
const nav = document.getElementById('primary-navigation')
navButton.addEventListener('click',openNavigation);
function openNavigation(){
const visibilty = nav.getAttribute('data-visible')
if(visibilty=== "false"){
nav.setAttribute("data-visible",true);
navButton.setAttribute("aria-expanded",true)
}
else {
nav.setAttribute("data-visible",false);
navButton.setAttribute("aria-expanded",false)
}
}
// DESTINATION PAGE
const moon = document.getElementById('moon')
const mars = document.getElementById('mars')
const europa = document.getElementById('europa')
const titan = document.getElementById('titan')
mars.addEventListener('click',()=>{
mars.setAttribute("aria-selected",true)
moon.setAttribute("aria-selected",false)
titan.setAttribute("aria-selected",false)
europa.setAttribute("aria-selected",false)
setDataForPlanets(1)
});
moon.addEventListener('click',()=>{
mars.setAttribute("aria-selected",false)
moon.setAttribute("aria-selected",true)
titan.setAttribute("aria-selected",false)
europa.setAttribute("aria-selected",false)
setDataForPlanets(0)
});
europa.addEventListener('click',()=>{
mars.setAttribute("aria-selected",false)
moon.setAttribute("aria-selected",false)
titan.setAttribute("aria-selected",false)
europa.setAttribute("aria-selected",true)
setDataForPlanets(2)
});
titan.addEventListener('click',()=>{
mars.setAttribute("aria-selected",false)
moon.setAttribute("aria-selected",false)
titan.setAttribute("aria-selected",true)
europa.setAttribute("aria-selected",false)
setDataForPlanets(3)
});
function setDataForPlanets(i){
document.getElementById('title').innerText = `${user.destinations[i].name}`
document.getElementById('description').innerText = `${user.destinations[i].description}`
document.getElementById('distance').innerText = `${user.destinations[i].distance}`
document.getElementById('time').innerText = `${user.destinations[i].travel}`
document.getElementById('webp-image').srcset=`${user.destinations[i].images.webp}`
document.getElementById('png-image').src=`${user.destinations[i].images.webp}`
}