-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathindex.js
160 lines (116 loc) · 4.06 KB
/
index.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const RESPONSIVE_WIDTH = 1024
let isHeaderCollapsed = window.innerWidth < RESPONSIVE_WIDTH
const collapseHeaderItems = document.getElementById("collapsed-items")
const collapseBtn = document.getElementById("collapse-btn")
gsap.registerPlugin(ScrollTrigger)
const flipImage = document.querySelector("#flip-image")
gsap.to(flipImage, {
scale: 1,
translateY: 0,
// translateY: "0%",
rotateX: "0deg",
scrollTrigger: {
trigger: "#flip-section",
start: window.innerWidth > RESPONSIVE_WIDTH ? "top 95%" : "top 70%",
end: "bottom bottom",
scrub: 1,
// markers: true,
}
})
function onHeaderClickOutside(e){
if (!collapseHeaderItems.contains(e.target)){
toggleHeader()
}
}
function toggleHeader(){
// console.log("Colappse", isHeaderCollapsed)
if (isHeaderCollapsed){
// collapseHeaderItems.classList.remove("max-md:tw-opacity-0")
collapseHeaderItems.classList.add("opacity-100")
collapseHeaderItems.style.width = "60vw"
collapseBtn.classList.remove("bi-list")
collapseBtn.classList.add("bi-x")
isHeaderCollapsed = false
setTimeout(() => window.addEventListener("click", onHeaderClickOutside), 1)
}else{
collapseHeaderItems.classList.remove("opacity-100")
collapseHeaderItems.style.width = "0vw"
collapseBtn.classList.remove("bi-x")
collapseBtn.classList.add("bi-list")
isHeaderCollapsed = true
window.removeEventListener("click", onHeaderClickOutside)
}
}
function responsive(){
if (window.innerWidth > RESPONSIVE_WIDTH){
collapseHeaderItems.style.width = ""
}
}
// function
window.addEventListener("resize", responsive)
const dropdowns = document.querySelectorAll('.dropdown')
dropdowns.forEach(dropdown => new Dropdown(`#${dropdown.id}`))
const cursor = document.querySelector('.cursor')
function isTouchDevice() {
return (('ontouchstart' in window) ||
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0))
}
function cursorPosUpdate(e){
cursor.style.display = 'block'
cursor.style.left = e.clientX + 'px'
cursor.style.top = e.clientY + 'px'
}
function hideCursor(){
cursor.style.display = 'none'
}
function addCursorListeners(){
if (!isTouchDevice() || window.innerWidth > RESPONSIVE_WIDTH) {
document.addEventListener('mousemove', cursorPosUpdate)
window.addEventListener("blur", hideCursor)
} else {
hideCursor()
document.removeEventListener('mousemove', cursorPosUpdate)
window.removeEventListener("blur", hideCursor)
}
}
addCursorListeners()
window.addEventListener("resize", () => {
addCursorListeners()
})
window.addEventListener("focus", () => {
addCursorListeners()
})
const slidingImageContainer = document.querySelector("#sliding-images")
/**
* Contains the sliding image path
*/
const images = [
"./assets/images/slideshow/women1.jpg",
"./assets/images/slideshow/women2.jpg",
"./assets/images/slideshow/women3.jpg",
"./assets/images/slideshow/women4.jpg",
"./assets/images/slideshow/women5.jpg",
"./assets/images/slideshow/women6.jpg",
]
function addSlidingImages(img){
const imageContainer = `
<div class="tw-min-w-[350px] tw-w-[350px] tw-h-[350px]
tw-overflow-clip tw-bg-black sliding-image">
<img src="${img}"
alt="" class="tw-object-cover tw-w-full tw-h-full">
</div>
`
slidingImageContainer.innerHTML += imageContainer
}
images.forEach( img => addSlidingImages(img))
images.forEach( img => addSlidingImages(img))
const sliding = gsap.to(slidingImageContainer, {
x: '-50%', // Adjust based on your actual element width to ensure it scrolls out of view
ease: "none",
duration: 80, // Initial duration in seconds
repeat: -1, // Infinite loop
})
// Event listeners for mouse hover
slidingImageContainer.addEventListener('mouseenter', () => sliding.timeScale(0.5)) // Slow down on hover
slidingImageContainer.addEventListener('mouseleave', () => sliding.timeScale(1)) // Return to original speed