-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (95 loc) · 3.18 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const entities = [
{
city: 'Rostov-On-Don <br> LCD Admiral',
area: '81 m2',
time: '3.5 months',
cost: 'Upon request',
img: './Admiral.png'
},
{
city: 'Sochi <br> Thieves',
area: '105 m2',
time: '4 months',
cost: 'Upon request',
img: './Thieves.png'
},
{
city: 'Rostov-On-Don <br> Patriotic',
area: '93 m2',
time: '3 months',
cost: 'Upon request',
img: './Patriotic.png'
}
]
const current_city = document.querySelector('#city')
const current_area = document.querySelector('#area')
const current_repair_time = document.querySelector('#repair-time')
const current_repair_cost = document.querySelector('#repair-cost')
const current_image = document.querySelector('#picture')
const setEntity = (index) => {
// fade out the current image
current_image.classList.add('fade')
// wait for the transition to complete
current_image.addEventListener('transitionend', () => {
// set the new image source
current_image.setAttribute('src', `${entities[index].img}`);
// fade in the new image
current_image.classList.remove('fade')
}, {once: true})
document.querySelectorAll('.info').forEach(info => info.classList.add('fade'))
document.querySelectorAll('.info').forEach(info => info.addEventListener('transitionend', () =>
{
current_city.innerHTML = entities[index].city
current_area.innerText = entities[index].area
current_repair_time.innerText = entities[index].time
current_repair_cost.innerText = entities[index].cost
info.classList.remove('fade')
}))
// remove "active" class from all nav elements
admiral.classList.remove("active");
thieves.classList.remove("active");
patriotic.classList.remove("active");
// add "active" class to the currently active nav element
if (index === 0) {
admiral.classList.add("active");
} else if (index === 1) {
thieves.classList.add("active");
} else if (index === 2) {
patriotic.classList.add("active");
}
document.querySelectorAll('.circle').forEach(circle => circle.classList.remove('active'));
document.querySelector(`#circle${index + 1}`).classList.add('active');
}
const prev = document.querySelector('#prev')
const next = document.querySelector('#next')
const admiral = document.querySelector('#Admiral')
const thieves = document.querySelector('#Thieves')
const patriotic = document.querySelector('#Patriotic')
let currentIndex = 0
prev.addEventListener('click', () => {
if (currentIndex === 0) {
currentIndex = entities.length
}
setEntity(currentIndex - 1);
currentIndex -= 1;
})
next.addEventListener('click', () => {
if (currentIndex === entities.length - 1) {
currentIndex = -1
}
setEntity(currentIndex + 1);
currentIndex += 1;
})
admiral.addEventListener('click', () => {
currentIndex = 0;
setEntity(currentIndex)
})
thieves.addEventListener('click', () => {
currentIndex = 1;
setEntity(currentIndex)
})
patriotic.addEventListener('click', () => {
currentIndex = 2;
setEntity(currentIndex)
})
setEntity(currentIndex)