marquee-content 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/code_of_conduct.md +37 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/index.module.js +149 -0
- package/dist/index.module.js.map +1 -0
- package/package.json +21 -24
- package/src/index.js +194 -0
- package/dist/index.html +0 -150
- package/dist/js/marquee-content.min.js +0 -2
- package/dist/js/marquee-content.min.js.LICENSE.txt +0 -29
- package/src/index.html +0 -150
- package/src/js/index.js +0 -3
- package/src/js/marquee-content.js +0 -180
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import gsap from 'gsap'
|
|
2
|
-
import ScrollTrigger from 'gsap/ScrollTrigger.js'
|
|
3
|
-
|
|
4
|
-
gsap.registerPlugin(ScrollTrigger)
|
|
5
|
-
|
|
6
|
-
const MarqueeContent = () => {
|
|
7
|
-
const marquees = document.querySelectorAll('.marquee-content')
|
|
8
|
-
|
|
9
|
-
for (const marquee of marquees) {
|
|
10
|
-
let matchMedia = gsap.matchMedia(),
|
|
11
|
-
dataSkew = marquee.dataset.mcSkew,
|
|
12
|
-
dataDuration = marquee.dataset.mcDuration || 20,
|
|
13
|
-
dataDirection = marquee.dataset.mcDirection,
|
|
14
|
-
dataMaxWidth = marquee.dataset.mcMax,
|
|
15
|
-
dataMinWidth = marquee.dataset.mcMin,
|
|
16
|
-
breakpoint
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
debounce = (fn, delay) => {
|
|
21
|
-
let timer
|
|
22
|
-
|
|
23
|
-
return (...args) => {
|
|
24
|
-
if (timer) clearTimeout(timer)
|
|
25
|
-
timer = setTimeout(() => fn(...args), delay)
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
breakpoints = () => {
|
|
30
|
-
breakpoint = dataMaxWidth ?
|
|
31
|
-
`(max-width: ${dataMaxWidth - 0.02}px)` : dataMinWidth ?
|
|
32
|
-
`(min-width: ${dataMinWidth}px)` : ``
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
templates = () => {
|
|
36
|
-
marquee.innerHTML = `
|
|
37
|
-
<div class="marquee-wrapper">
|
|
38
|
-
<div class="marquee-inner" style="display: inline-block; white-space: nowrap;">${marquee.innerHTML}</div>
|
|
39
|
-
</div>
|
|
40
|
-
`
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
cloning = () => {
|
|
44
|
-
const removingClones = () => {
|
|
45
|
-
while (marquee.childElementCount > 1) {
|
|
46
|
-
marquee.removeChild(marquee.lastChild)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
removingClones()
|
|
51
|
-
|
|
52
|
-
matchMedia.add(breakpoint, () => {
|
|
53
|
-
let requiredQuantity = Math.ceil((marquee.scrollWidth / marquee.firstElementChild.clientWidth) + 2)
|
|
54
|
-
|
|
55
|
-
if (marquee.childElementCount < requiredQuantity) {
|
|
56
|
-
for (let i = 1; i < (requiredQuantity); i++) {
|
|
57
|
-
let cloned = marquee.firstElementChild
|
|
58
|
-
let clone = cloned.cloneNode(true)
|
|
59
|
-
cloned.parentNode.append(clone)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return () => {
|
|
64
|
-
removingClones()
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
skewed = () => {
|
|
70
|
-
if(!dataSkew) return
|
|
71
|
-
|
|
72
|
-
let abs = Math.abs(parseInt(dataSkew)),
|
|
73
|
-
style = marquee.style
|
|
74
|
-
|
|
75
|
-
matchMedia.add(breakpoint, () => {
|
|
76
|
-
style.transformOrigin = 'center center'
|
|
77
|
-
style.transform = `skew(0deg, ${dataSkew}deg)`
|
|
78
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
|
|
79
|
-
|
|
80
|
-
return () => {
|
|
81
|
-
style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
animation = () => {
|
|
87
|
-
let timeLine = gsap.timeline()
|
|
88
|
-
|
|
89
|
-
timeLine.kill()
|
|
90
|
-
timeLine = null
|
|
91
|
-
|
|
92
|
-
gsap.set(marquee.children, { clearProps: true })
|
|
93
|
-
|
|
94
|
-
matchMedia.add(breakpoint, () => {
|
|
95
|
-
gsap.set(marquee.children, { 'will-change': 'transform' })
|
|
96
|
-
|
|
97
|
-
const tween = gsap.to(marquee.children, {
|
|
98
|
-
duration: dataDuration,
|
|
99
|
-
x: '-100%',
|
|
100
|
-
ease: 'none',
|
|
101
|
-
repeat: -1,
|
|
102
|
-
scrollTrigger: {
|
|
103
|
-
trigger: marquee,
|
|
104
|
-
start: '-=50% bottom',
|
|
105
|
-
end: 'bottom top',
|
|
106
|
-
toggleActions: 'resume pause resume pause'
|
|
107
|
-
},
|
|
108
|
-
}).totalProgress(0.5)
|
|
109
|
-
|
|
110
|
-
const ltrDirection = () => {
|
|
111
|
-
gsap.to(tween, {
|
|
112
|
-
timeScale: -1,
|
|
113
|
-
overwrite: true
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const autoDirection = () => {
|
|
118
|
-
let previousScrollPosition = 0
|
|
119
|
-
|
|
120
|
-
const isScrollingDown = () => {
|
|
121
|
-
let scrollPosition = window.pageYOffset || document.documentElement.scrollTop
|
|
122
|
-
|
|
123
|
-
let direction = false
|
|
124
|
-
|
|
125
|
-
if (scrollPosition > previousScrollPosition) {
|
|
126
|
-
direction = true
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition
|
|
130
|
-
|
|
131
|
-
gsap.to(tween, {
|
|
132
|
-
timeScale: direction ? -1 : 1,
|
|
133
|
-
overwrite: true
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
addEventListener('scroll', isScrollingDown, {
|
|
138
|
-
capture: true,
|
|
139
|
-
passive: true
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if(dataDirection === 'ltr') {
|
|
144
|
-
ltrDirection()
|
|
145
|
-
} else if(dataDirection === 'auto') {
|
|
146
|
-
autoDirection()
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
update = () => {
|
|
152
|
-
skewed()
|
|
153
|
-
cloning()
|
|
154
|
-
animation()
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
init = () => {
|
|
158
|
-
breakpoints()
|
|
159
|
-
templates()
|
|
160
|
-
|
|
161
|
-
matchMedia.add('(any-pointer: coarse)', () => {
|
|
162
|
-
addEventListener('orientationchange', () => update())
|
|
163
|
-
}).add('(any-pointer: fine)', () => {
|
|
164
|
-
addEventListener('resize', debounce(() => update(), 250))
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
document.fonts.ready.then(() => {
|
|
168
|
-
update()
|
|
169
|
-
}).catch(() => {
|
|
170
|
-
update()
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
init()
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export {
|
|
179
|
-
MarqueeContent
|
|
180
|
-
}
|