-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
126 lines (97 loc) · 3.21 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
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
124
125
/*~~~~~~~~~~~~~~~ TOGGLE BUTTON ~~~~~~~~~~~~~~~*/
const navMenu = document.getElementById("nav-menu")
const navLink = document.querySelectorAll(".nav-link")
const hamburger = document.getElementById("hamburger")
hamburger.addEventListener("click", () => {
navMenu.classList.toggle("left-[0]")
hamburger.classList.toggle('ri-close-large-line')
})
navLink.forEach(link => {
link.addEventListener("click", () => {
navMenu.classList.toggle("left-[0]")
hamburger.classList.toggle('ri-close-large-line')
})
})
/*~~~~~~~~~~~~~~~ SHOW SCROLL UP ~~~~~~~~~~~~~~~*/
const scrollup = () => {
const scrollupBtn = document.getElementById("scroll-up")
if (this.scrollY >= 250) {
scrollupBtn.classList.remove("-bottom-1/2")
scrollupBtn.classList.add("bottom-4")
} else {
scrollupBtn.classList.add("-bottom-1/2")
scrollupBtn.classList.remove("bottom-4")
}
}
window.addEventListener("scroll", scrollup)
/*~~~~~~~~~~~~~~~ CHANGE BACKGROUND HEADER ~~~~~~~~~~~~~~~*/
const scrollHeader = () => {
const header = document.getElementById("navbar")
if (this.scrollY >= 50) {
header.classList.add("border-b", "border-yellow-500")
} else {
header.classList.remove("border-b", "border-yellow-500")
}
}
window.addEventListener("scroll", scrollHeader)
/*~~~~~~~~~~~~~~~ SWIPER ~~~~~~~~~~~~~~~*/
const swiper = new Swiper('.swiper', {
// Optional parameters
speed: 400,
spaceBetween: 30,
autoplay: {
delay: 3000,
disableOnInteraction: false
},
// If we need pagination
pagination: {
el: '.swiper-pagination',
clickable: true
},
grabCursor: true,
breakpoints: {
640: {
slidesPerView: 1
},
768: {
slidesPerView: 2
},
1024: {
slidesPerView: 3
},
}
});
/*~~~~~~~~~~~~~~~ SCROLL SECTIONS ACTIVE LINK ~~~~~~~~~~~~~~~*/
const activeLink = () => {
const sections = document.querySelectorAll('section')
const navLinks = document.querySelectorAll(".nav-link")
let current = "home"
sections.forEach(section => {
const sectionTop = section.offsetTop;
if (this.scrollY >= sectionTop - 60) {
current = section.getAttribute("id")
}
})
navLinks.forEach(item => {
item.classList.remove("active")
if (item.href.includes(current)) {
item.classList.add("active")
}
})
}
window.addEventListener("scroll", activeLink)
/*~~~~~~~~~~~~~~~ SCROLL REVEAL ANIMATION ~~~~~~~~~~~~~~~*/
const sr = ScrollReveal({
origin: "top",
distance: "60px",
duration: 2500,
delay: 300,
reset: true
})
sr.reveal(`.home__data, .about__top, .popular__top, .review__top, .review__swiper, .footer__icon, .footer__content, .copy__right`)
sr.reveal(`.home__image`, { delay: 500, scale: 0.5 })
sr.reveal(`.service__card, .popular_card`, { interval: 100 })
sr.reveal(`.about__leaf`, { delay: 1000, origin: "right" })
sr.reveal(`.about__item__1-content, .about__item__2-img`, { origin: "right" })
sr.reveal(`.about__item__2-content, .about__item__1-img`, { origin: "left" })
sr.reveal(`.review__leaf, .footer__floral`, { delay: 1000, origin: "left" })