-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (62 loc) · 1.69 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Mobile Navigation functionality */
const mobileBar = document.getElementById("bar");
const nav = document.getElementById("navbar");
const close = document.getElementById("close");
if (mobileBar) {
mobileBar.addEventListener("click", function () {
nav.classList.add("active");
});
}
if (close) {
close.addEventListener("click", function () {
nav.classList.remove("active");
});
}
/* Show Detail Image SLide */
const mainImg = document.getElementById("main--image");
const smallImg = document.getElementsByClassName("small-img");
for (const img of smallImg) {
img.onclick = () => {
mainImg.src = img.src;
};
}
// Go to Detail page
const productCard = document.getElementsByClassName("pro");
for (const card of productCard) {
card.onclick = () => {
location.href = "../product/sproduct.html";
};
}
// Read More Functionality
const readMore = document.getElementById("read-more");
const readMoreText = document.getElementById("read-more-text");
if (readMore) {
// To show the text
const showReadMoreText = () => {
readMore.textContent = "read less";
readMoreText.style.display = "inline";
};
// To hide the text
const hideReadMoreText = () => {
readMore.textContent = "read more...";
readMoreText.style.display = "none";
};
let isOpen = false;
readMore.addEventListener("click", () => {
if (!isOpen) {
showReadMoreText();
isOpen = true;
} else {
hideReadMoreText();
isOpen = false;
}
});
// if the screen size is lager than 799 px the read more text will be shown
window.addEventListener("resize", () => {
if (window.innerWidth >= 799) {
showReadMoreText();
} else {
hideReadMoreText();
}
});
}