-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.js
96 lines (78 loc) · 3.01 KB
/
app.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
const intViewportWidth = window.innerWidth;
const intViewportHeight = window.innerHeight;
const catogorySlide = () => {
const burger = document.querySelector('.burger');
const section = document.querySelector('.catogories');
const display = document.querySelector('.display');
const overlay = document.querySelector('.overlay');
burger.addEventListener('click', () => {
section.classList.toggle('catogories-active');
burger.classList.toggle('burger-active');
if(intViewportWidth>intViewportHeight){
display.classList.remove('display-active');
}
overlay.classList.toggle('overlay-active');
});
}
const sectionDisplay = () => {
const catogory = document.querySelectorAll('.catogories-links li');
const display = document.querySelector('.display');
catogory.forEach((item) => {
item.addEventListener('click', () => {
if(intViewportWidth>intViewportHeight){
display.classList.toggle('display-active');
}
});
})
}
const navScroll = () => {
const nav = document.querySelector('nav');
const logo = document.querySelector('.logo');
const links = document.querySelector('.customer-section');
const burger = document.querySelectorAll('.burger-line');
window.addEventListener('scroll', () => {
if(window.scrollY >= 6*nav.offsetHeight){
nav.classList.add('nav-dark');
links.classList.add('customer-section-dark');
logo.classList.add('logo-dark');
} else {
nav.classList.remove('nav-dark');
links.classList.remove('customer-section-dark');
logo.classList.remove('logo-dark');
}
});
}
const carousel = () => {
const carousel = document.querySelector(".recent");
const card = carousel.querySelector(".recent .small-promo");
const leftButton = document.querySelector(".button-wrapper .slideLeft");
const rightButton = document.querySelector(".button-wrapper .slideRight");
const carouselWidth = carousel.offsetWidth;
const cardStyle = card.currentStyle || window.getComputedStyle(card)
const cardMarginRight = Number(cardStyle.marginRight.match(/\d+/g)[0]);
const cardWidth = card.offsetWidth;
let offset = 0;
let max = carouselWidth - 3*(cardWidth+cardMarginRight);
console.log(`Max = ${max}`);
leftButton.addEventListener("click", function() {
if (offset/(cardWidth + cardMarginRight) !== 0) {
offset += cardWidth + cardMarginRight;
carousel.scrollLeft -= cardWidth + cardMarginRight;
console.log(carousel.scrollLeft);
}
})
rightButton.addEventListener("click", function() {
if (offset/(cardWidth + cardMarginRight) !== -5) {
offset += cardWidth + cardMarginRight;
carousel.scrollLeft += cardWidth + cardMarginRight;
console.log(carousel.scrollLeft);
}
})
}
const start = () => {
catogorySlide();
sectionDisplay();
navScroll();
carousel();
}
start();