-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
123 lines (97 loc) · 3 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
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
function selectSize(button) {
// Remove the "selected" class from all buttons
var buttons = document.getElementsByClassName("size-btn");
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.remove("selected");
}
// Add the "selected" class to the clicked button
button.classList.add("selected");
}
/*
var MainImg = document.getElementById('MainImg');
var smallImg = document.getElementsByClassName('small-img');
smallImg[0].onclick = function(){
MainImg.src = smallImg[0].src;
}
smallImg[1].onclick = function(){
MainImg.src = smallImg[1].src;
}
smallImg[2].onclick = function(){
MainImg.src = smallImg[2].src;
}
smallImg[3].onclick = function(){
MainImg.src = smallImg[3].src;
}
*/
$(document).ready(function() {
var counterValue = 1;
$('.minus-btn').click(function() {
if (counterValue > 1) {
counterValue--;
$('.counter-value').text(counterValue);
}
});
$('.plus-btn').click(function() {
counterValue++;
$('.counter-value').text(counterValue);
});
});
/*
$(document).ready(function() {
$('.next-btn').click(function() {
$('.cardProduct').animate({ scrollLeft: '+=200' }, 'slow');
});
$('.prev-btn').click(function() {
$('.cardProduct').animate({ scrollLeft: '-=200' }, 'slow');
});
});
*/
$(document).ready(function() {
var cardContainer = $('.divProducts');
var cardWidth = $('.cardProduct').outerWidth(true);
var cardsToShow = 2;
var scrollAmount = cardWidth * cardsToShow;
// Adjust card visibility on window resize
$(window).on('resize', function() {
if ($(window).width() < 780) {
cardsToShow = 2;
scrollAmount = cardWidth * cardsToShow;
} else {
cardsToShow = 4;
scrollAmount = cardWidth * cardsToShow;
cardContainer.css('transform', '');
}
}).resize();
$('.next-btn').click(function() {
cardContainer.animate({ scrollLeft: '+=' + scrollAmount }, 'slow');
});
$('.prev-btn').click(function() {
cardContainer.animate({ scrollLeft: '-=' + scrollAmount }, 'slow');
});
});
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.querySelector('.menu-toggle');
const menu = document.querySelector('.menu');
menuToggle.addEventListener('click', function() {
menu.classList.toggle('active');
});
});
document.addEventListener('DOMContentLoaded', function() {
const dropdowns = document.querySelectorAll('.dropdown');
dropdowns.forEach(function(dropdown) {
const trigger = dropdown.querySelector('a');
const menu = dropdown.querySelector('.dropdown-menu');
trigger.addEventListener('click', function(e) {
e.preventDefault();
dropdowns.forEach(function(dropdown) {
dropdown.classList.remove('active');
});
dropdown.classList.add('active');
});
document.addEventListener('click', function(e) {
if (!dropdown.contains(e.target)) {
dropdown.classList.remove('active');
}
});
});
});