-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (48 loc) · 1.71 KB
/
script.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
function openCloseMenu() {
var menuBar = document.getElementById("menu-bar");
var content = document.getElementById("content");
if (menuBar.style.width === "250px") {
menuBar.style.width = "0";
content.style.marginLeft = "0";
} else {
menuBar.style.width = "250px";
content.style.marginLeft = "250px";
}
}
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
if (!event.target.matches(".dropbtn")) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains("show")) {
openDropdown.classList.remove("show");
}
}
}
};
document.addEventListener('DOMContentLoaded', () => {
fetch('products.json')
.then(response => response.json())
.then(data => {
const productSlider = document.getElementById('product-slider');
data.forEach(product => {
const productElement = document.createElement('div');
productElement.classList.add('product');
productElement.innerHTML = `
<img src="${product.image}" alt="${product.name}">
<h3>${product.name}</h3>
<p>${product.price}</p>
<button>Order Now !</button>
`;
productSlider.appendChild(productElement);
});
})
.catch(error => console.error('Error fetching products:', error));
});