-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
91 lines (68 loc) · 2.01 KB
/
main.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
import "./style.css";
import products from "./API/products.json";
import { showProductContainer } from "./HomeProductCards";
showProductContainer(products);
// Smooth scrolling script
document.querySelectorAll('.nav-item a[href*="#"]').forEach((item) => {
item.addEventListener('click', (event) => {
event.preventDefault();
const href = item.getAttribute('href');
let targetId = href.substring(1);
const idMap = {
products: "products_redirect",
home: "home_redirect",
about: "about_redirect",
contact: "contact_redirect"
};
if (idMap[targetId]) {
targetId = idMap[targetId];
}
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
});
}
});
});
// FOR SMOOTHSCROLLING OF LAST FOOTER
document.querySelectorAll(".last_footer a").forEach((link) => {
link.addEventListener("click", (event) => {
event.preventDefault();
const href = link.getAttribute("href").substring(1);
const idMap = {
home: "home_redirect",
about: "about_redirect",
products: "products_redirect",
contact: "contact_redirect",
};
const targetId = idMap[href];
if (targetId) {
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
}
});
});
// EXPLORE THE PRODUCTS SMOOTH SCROLLING
document.querySelectorAll('a[href*="#"]').forEach((link) => {
link.addEventListener("click", (event) => {
event.preventDefault();
const href = link.getAttribute("href").substring(1);
const idMap = {
products: "products_redirect",
};
const targetId = idMap[href] || href;
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
});