-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
46 lines (41 loc) · 1.12 KB
/
scripts.js
File metadata and controls
46 lines (41 loc) · 1.12 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
/* Fetch static data */
fetch("./data/data.json")
.then(function (response) {
return response.json();
})
.then(function (data) {
appendData(data);
})
.catch(function (err) {
console.log("error: " + err);
});
let htmlCode = ``;
function appendData(data) {
data.cakes.forEach((cake) => {
htmlCode =
htmlCode +
`<div class="menu__card" id="${cake.id}">
<img src="${cake.image}" alt="${cake.title}">
<h4>${cake.title}</h4>
<p class="card__desc">${cake.previewDescription}</p>
<div class="price">
<p>${"₹" + cake.price[0] + "/-"}</p>
<button class="btn">View Details</button>
</div>
</div>`;
});
const cakeCards = document.querySelector(".card__cont");
cakeCards.innerHTML = htmlCode;
}
//* window onScroll navbar shrink */
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
const header = document.getElementById("header");
if (document.body.scrollTop > 90 || document.documentElement.scrollTop > 90) {
header.classList.add("header__shrink");
} else {
header.classList.remove("header__shrink");
}
}