-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
220 lines (167 loc) · 6.33 KB
/
js.js
File metadata and controls
220 lines (167 loc) · 6.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
const navBtn = document.querySelector('.nav-btn');
const nav = document.querySelector('header');
navBtn.onclick = function () {
nav.classList.toggle('header-top-row');
};
const crossBtn = document.querySelector('.cross');
crossBtn.onclick = function () {
nav.classList.toggle('header-top-row');
};
const contplaces = document.querySelector('.content-places');
const allCards = Array.from(document.querySelectorAll('.place-card'));
const leftButton = document.querySelector('.destination-left');
const rightButton = document.querySelector('.destination-right');
let cards = [];
let currentIndex = 0;
function getSlideFullWidth(slide) {
const style = getComputedStyle(slide);
const marginLeft = parseFloat(style.marginLeft);
const marginRight = parseFloat(style.marginRight);
return slide.clientWidth + marginLeft + marginRight;
}
function adjustSlides() {
console.log("Ширина вікна: ", window.innerWidth);
if (window.innerWidth > 1900) {
cards = allCards.slice(0, 3);
} else if (window.innerWidth < 350) {
cards = allCards.slice(0, 5);
} else {
cards = allCards.slice(0, 5);
}
console.log("Кількість слайдів: ", cards.length);
currentIndex = Math.min(currentIndex, cards.length - 1);
updateSlider();
}
function updateSlider() {
if (cards.length === 0) return;
const slideWidth = getSlideFullWidth(cards[0]);
contplaces.style.transform = `translateX(-${currentIndex * slideWidth}px)`;
}
leftButton.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : cards.length - 1;
updateSlider();
});
rightButton.addEventListener('click', () => {
currentIndex = (currentIndex < cards.length - 1) ? currentIndex + 1 : 0;
updateSlider();
});
window.addEventListener('load', adjustSlides);
window.addEventListener('resize', adjustSlides);
adjustSlides();
const offers = document.querySelector('.Offers-list');
const offerCards = Array.from(document.querySelectorAll('.Offer-card'));
const specialLeft = document.querySelector('.special-left');
const specialRight = document.querySelector('.special-right');
let Offs = [];
let nowIndex = 0;
function getFullwidth(cart) {
const Sty = getComputedStyle(cart);
const MarginL = parseFloat(Sty.marginLeft);
const MarginR = parseFloat(Sty.marginRight);
return cart.clientWidth + MarginL + MarginR;
}
function adcarts() {
console.log("Ширина вікна: ", window.innerWidth);
if (window.innerWidth < 1900) {
Offs = offerCards.slice(0, 3);
console.log("Кількість слайдів: ", Offs.length);
nowIndex = Math.min(nowIndex, Offs.length - 1);
} else {
Offs = [];
offers.style.transform = '';
}
}
function updateCart() {
if (Offs.length === 0) return;
const cartWidth = getFullwidth(Offs[0]);
offers.style.transform = `translateX(-${nowIndex * cartWidth}px)`;
}
specialLeft.addEventListener('click', () => {
nowIndex = (nowIndex > 0) ? nowIndex - 1 : Offs.length - 1;
updateCart();
});
specialRight.addEventListener('click', () => {
nowIndex = (nowIndex < Offs.length - 1) ? nowIndex + 1 : 0;
updateCart();
});
window.addEventListener('load', adcarts);
window.addEventListener('resize', adcarts);
adcarts();
document.getElementById("toogleButton").addEventListener("click", function() {
const droptext = document.getElementById("DropText");
if (droptext.classList.contains("hidden-text")) {
droptext.classList.remove("hidden-text");
droptext.classList.add("visible");
this.innerHTML = `Read Less `;
} else {
droptext.classList.remove("visible");
droptext.classList.add("hidden-text")
this.innerHTML = `Read More`;
}
});
const Trip = document.querySelectorAll('.Trip-Image');
const Utrip = document.querySelectorAll('.Under-Image');
function addEventListenersIfLargeScreen() {
if (window.innerWidth > 1900) {
Trip.forEach((trip, index) => {
let isTripMoved = false;
trip.addEventListener('click', () => {
const utrip = Utrip[index];
if (isTripMoved) {
trip.style.transform = 'translateY(0px)';
if (utrip) {
utrip.style.transform = 'translateY(0px)';
}
} else {
trip.style.transform = 'translateY(-73px)';
if (utrip) {
utrip.style.transform = 'translateY(270px)';
}
}
isTripMoved = !isTripMoved;
});
});
}
}
addEventListenersIfLargeScreen();
const contentPlaces = document.querySelector('.react-list');
const allPlaceCards = Array.from(document.querySelectorAll('.react-list-element'));
const leftArrowButton = document.querySelector('.react-left');
const rightArrowButton = document.querySelector('.react-right');
let visibleCards = [];
let activeCardIndex = 0;
function calculateSlideFullWidth(slide) {
const slideStyle = getComputedStyle(slide);
const marginLeft = parseFloat(slideStyle.marginLeft);
const marginRight = parseFloat(slideStyle.marginRight);
return slide.clientWidth + marginLeft + marginRight;
}
function updateVisibleSlides() {
console.log("Window width: ", window.innerWidth);
if (window.innerWidth > 1900) {
visibleCards = allPlaceCards.slice(0, 2);
} else if (window.innerWidth < 350) {
visibleCards = allPlaceCards.slice(0, 3);
} else {
visibleCards = allPlaceCards.slice(0, 3);
}
console.log("Number of slides: ", visibleCards.length);
activeCardIndex = Math.min(activeCardIndex, visibleCards.length - 1);
refreshSliderPosition();
}
function refreshSliderPosition() {
if (visibleCards.length === 0) return;
const slideWidth = calculateSlideFullWidth(visibleCards[0]);
contentPlaces.style.transform = `translateX(-${activeCardIndex * slideWidth}px)`;
}
leftArrowButton.addEventListener('click', () => {
activeCardIndex = (activeCardIndex > 0) ? activeCardIndex - 1 : visibleCards.length - 1;
refreshSliderPosition();
});
rightArrowButton.addEventListener('click', () => {
activeCardIndex = (activeCardIndex < visibleCards.length - 1) ? activeCardIndex + 1 : 0;
refreshSliderPosition();
});
window.addEventListener('load', updateVisibleSlides);
window.addEventListener('resize', updateVisibleSlides);
updateVisibleSlides();