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
package/src/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
class MarqueeContent extends HTMLElement {
|
|
2
|
+
static registerGSAP(gsap) {
|
|
3
|
+
MarqueeContent.gsap = gsap
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
constructor(query) {
|
|
7
|
+
super()
|
|
8
|
+
|
|
9
|
+
this.gsap = MarqueeContent.gsap || window.gsap
|
|
10
|
+
this.MM = this.gsap.matchMedia(query)
|
|
11
|
+
this.dataSkew = this.dataset.mcSkew
|
|
12
|
+
this.dataDuration = this.dataset.mcDuration || 20
|
|
13
|
+
this.dataDirection = this.dataset.mcDirection
|
|
14
|
+
this.dataMaxWidth = this.dataset.mcMax
|
|
15
|
+
this.dataMinWidth = this.dataset.mcMin
|
|
16
|
+
this.breakpoint = this.dataMaxWidth
|
|
17
|
+
? `(max-width: ${this.dataMaxWidth - 0.02}px)`
|
|
18
|
+
: this.dataMinWidth
|
|
19
|
+
? `(min-width: ${this.dataMinWidth}px)`
|
|
20
|
+
: ''
|
|
21
|
+
this.debounce()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
debounce(fn, delay) {
|
|
25
|
+
let timer
|
|
26
|
+
|
|
27
|
+
return (...args) => {
|
|
28
|
+
if (timer) clearTimeout(timer)
|
|
29
|
+
timer = setTimeout(() => fn(...args), delay)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
templates() {
|
|
34
|
+
const div = document.createElement('div')
|
|
35
|
+
|
|
36
|
+
div.style.display = 'inline-block'
|
|
37
|
+
div.style.whiteSpace = 'nowrap'
|
|
38
|
+
|
|
39
|
+
while (this.firstChild) {
|
|
40
|
+
div.appendChild(this.firstChild)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.appendChild(div)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
cloning() {
|
|
47
|
+
const removingClones = () => {
|
|
48
|
+
while (this.childElementCount > 1) {
|
|
49
|
+
this.removeChild(this.lastChild)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
removingClones()
|
|
54
|
+
|
|
55
|
+
this.MM.add(this.breakpoint, () => {
|
|
56
|
+
let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)
|
|
57
|
+
|
|
58
|
+
if (this.childElementCount < requiredQuantity) {
|
|
59
|
+
for (let i = 1; i < requiredQuantity; i++) {
|
|
60
|
+
let cloned = this.firstElementChild
|
|
61
|
+
let clone = cloned.cloneNode(true)
|
|
62
|
+
cloned.parentNode.append(clone)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return () => {
|
|
67
|
+
removingClones()
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
skewed() {
|
|
73
|
+
if (!this.dataSkew) return
|
|
74
|
+
|
|
75
|
+
const abs = Math.abs(parseInt(this.dataSkew))
|
|
76
|
+
const style = this.style
|
|
77
|
+
|
|
78
|
+
this.MM.add(this.breakpoint, () => {
|
|
79
|
+
style.transformOrigin = 'center center'
|
|
80
|
+
style.transform = `skew(0deg, ${this.dataSkew}deg)`
|
|
81
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
animation() {
|
|
90
|
+
let timeLine = this.gsap.timeline()
|
|
91
|
+
|
|
92
|
+
timeLine.kill()
|
|
93
|
+
timeLine = null
|
|
94
|
+
|
|
95
|
+
this.gsap.set(this.children, { clearProps: true })
|
|
96
|
+
|
|
97
|
+
this.MM.add(this.breakpoint, () => {
|
|
98
|
+
this.gsap.set(this.children, { 'will-change': 'transform' })
|
|
99
|
+
|
|
100
|
+
const tween = this.gsap.to(this.children, {
|
|
101
|
+
duration: this.dataDuration,
|
|
102
|
+
x: '-100%',
|
|
103
|
+
ease: 'none',
|
|
104
|
+
repeat: -1,
|
|
105
|
+
scrollTrigger: {
|
|
106
|
+
trigger: this,
|
|
107
|
+
start: '-=50% bottom',
|
|
108
|
+
end: 'bottom top',
|
|
109
|
+
toggleActions: 'resume pause resume pause',
|
|
110
|
+
},
|
|
111
|
+
}).totalProgress(0.5)
|
|
112
|
+
|
|
113
|
+
const ltrDirection = () => {
|
|
114
|
+
this.gsap.to(tween, {
|
|
115
|
+
timeScale: -1,
|
|
116
|
+
overwrite: true
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const autoDirection = () => {
|
|
121
|
+
let previousScrollPosition = 0
|
|
122
|
+
|
|
123
|
+
const isScrollingDown = () => {
|
|
124
|
+
const scrollPosition = window.pageYOffset || document.documentElement.scrollTop
|
|
125
|
+
|
|
126
|
+
let direction = false
|
|
127
|
+
|
|
128
|
+
if (scrollPosition > previousScrollPosition) {
|
|
129
|
+
direction = true
|
|
130
|
+
} else if (scrollPosition < previousScrollPosition) {
|
|
131
|
+
direction = false
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition
|
|
135
|
+
|
|
136
|
+
return direction
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
addEventListener('scroll', this.debounce(() => {
|
|
140
|
+
const scrollDirection = isScrollingDown()
|
|
141
|
+
|
|
142
|
+
this.gsap.to(tween, {
|
|
143
|
+
timeScale: scrollDirection ? 1 : -1,
|
|
144
|
+
overwrite: true,
|
|
145
|
+
})
|
|
146
|
+
}, 50), {
|
|
147
|
+
capture: true, passive: true
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (this.dataDirection === 'ltr') {
|
|
152
|
+
ltrDirection()
|
|
153
|
+
} else if (this.dataDirection === 'auto') {
|
|
154
|
+
autoDirection()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
this.gsap.set(this.children, { clearProps: true })
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
onResize() {
|
|
164
|
+
cancelAnimationFrame(this.af)
|
|
165
|
+
|
|
166
|
+
this.af = requestAnimationFrame(() => {
|
|
167
|
+
this.cloning()
|
|
168
|
+
this.animation()
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
onUpdate() {
|
|
173
|
+
this.templates()
|
|
174
|
+
this.cloning()
|
|
175
|
+
this.skewed()
|
|
176
|
+
this.animation()
|
|
177
|
+
|
|
178
|
+
this.onResize = this.onResize.bind(this)
|
|
179
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))
|
|
180
|
+
this.resizeObserver.observe(this)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
connectedCallback() {
|
|
184
|
+
this.onUpdate()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
disconnectedCallback() {
|
|
188
|
+
this.MM.remove()
|
|
189
|
+
|
|
190
|
+
document.fonts.removeEventListener('loadingdone', this.onUpdate)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
customElements.define('marquee-content', MarqueeContent)
|
package/dist/index.html
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="ru">
|
|
3
|
-
<head>
|
|
4
|
-
<title>marquee-content</title>
|
|
5
|
-
<meta name="robots" content="none">
|
|
6
|
-
<meta charset="UTF-8">
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
|
8
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
9
|
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
|
|
10
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
11
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
12
|
-
<link href="https://fonts.googleapis.com/css2?family=Alkatra:wght@700&family=Anton&family=Lobster&family=PT+Sans+Narrow:wght@700&family=Prompt:wght@500&display=swap" rel="stylesheet">
|
|
13
|
-
<style type="text/css">
|
|
14
|
-
html{font-family: system-ui, -apple-system, "Open Sans", "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";font-size: 10px}body{margin: 150px 0 400px;font-feature-settings: "kern" 1,"liga" 0;font-size: 1.6rem;font-weight: 400;line-height: 1.5;color: #444}html,body,input,textarea,button{-webkit-font-smoothing: subpixel-antialiased}.marquee-content{pointer-events: none;max-width: 100vw;justify-content: center;align-items: center;display: flex;position: relative;overflow: hidden}.font{white-space: nowrap}.alkatra{font-family: 'Alkatra', cursive;font-weight: 700;font-size: 48px}.anton{font-family: 'Anton', sans-serif;font-weight: 700;font-size: 40px}.pt{font-family: 'PT Sans Narrow', sans-serif;font-weight: 400;font-size: 52px}.lobster{font-family: 'Lobster', cursive;font-weight: 400;font-size: 50px}.prompt{font-family: 'Prompt', sans-serif;font-weight: 500;font-size: 48px}ul{list-style: none;margin: 0;padding: 0;display: flex;align-items: center}li{padding: 0 10px;text-align: center}.example-1 li{padding: 0 0 0 66px;background:url("data:image/svg xml,<svg width='26' height='26' viewBox='0 0 26 26' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M15.0527 10.9474L13 0L10.9473 10.9474L0 13L10.9473 15.0526L13 26L15.0527 15.0526L26 13L15.0527 10.9474Z' fill='#444444'/></svg>")center left 20px / 26px 26pxno-repeat}.example-2 li{padding: 0 15px}.example-3 li{position: relative;padding: 0 0 0 56px}.example-3 li::before{content: '';position: absolute;top: 0;right: -33px;bottom: 0;left: auto;margin: auto;width: 7px;height: 7px;transform: translateY(5px);background: #444;border-radius: 100%}.example-4{text-transform: uppercase}.data-code{margin: 80px auto 30px;padding: 0 20px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
|
|
15
|
-
</style>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<section class="data-code">
|
|
19
|
-
<strong>data-mc-duration="60"</strong>
|
|
20
|
-
<p>The basic version, with scrolling content from right to left</p>
|
|
21
|
-
</section>
|
|
22
|
-
<section class="example-1">
|
|
23
|
-
<div class="marquee-content"
|
|
24
|
-
data-mc-duration="60"
|
|
25
|
-
role="marquee">
|
|
26
|
-
<ul class="font alkatra">
|
|
27
|
-
<li>Monarch</li>
|
|
28
|
-
<li>Benassi</li>
|
|
29
|
-
<li>Air Max</li>
|
|
30
|
-
<li>Cortez</li>
|
|
31
|
-
<li>Jordan</li>
|
|
32
|
-
<li>Presto</li>
|
|
33
|
-
<li>Vomero</li>
|
|
34
|
-
<li>Pegasus</li>
|
|
35
|
-
</ul>
|
|
36
|
-
</div>
|
|
37
|
-
</section>
|
|
38
|
-
<section class="data-code">
|
|
39
|
-
<strong>data-mc-duration="20"</strong>
|
|
40
|
-
<p>Images scrolling</p>
|
|
41
|
-
</section>
|
|
42
|
-
<section class="example-7">
|
|
43
|
-
<div class="marquee-content"
|
|
44
|
-
data-mc-duration="20"
|
|
45
|
-
role="marquee">
|
|
46
|
-
<ul>
|
|
47
|
-
<li><img src="//fastly.picsum.photos/id/634/180/100.jpg?hmac=qB-PFAiiEVuXFwVxRbYUzImrQ4RZ2np6oWeK-XHPnXk" alt></li>
|
|
48
|
-
<li><img src="//fastly.picsum.photos/id/719/180/100.jpg?hmac=_Toti9aQVjjnNHabofyq_la4a0kIFSDp3o65zxnvtRY" alt></li>
|
|
49
|
-
<li><img src="//fastly.picsum.photos/id/235/180/100.jpg?hmac=5KlYbDb93R7me0GThn6FFoK_OZ8ziPn-fb98FHIMb5c" alt></li>
|
|
50
|
-
<li><img src="//fastly.picsum.photos/id/1050/180/100.jpg?hmac=f9i0nGYKBetkohJors44GETXmUhSbLcXMUlSvMCluJY" alt></li>
|
|
51
|
-
</ul>
|
|
52
|
-
</div>
|
|
53
|
-
</section>
|
|
54
|
-
<section class="data-code">
|
|
55
|
-
<strong>data-mc-duration="60" data-mc-direction="ltr"</strong>
|
|
56
|
-
<p><code>data-mc-direction="ltr"</code> — changes the scroll direction from left to right</p>
|
|
57
|
-
</section>
|
|
58
|
-
<section class="example-2">
|
|
59
|
-
<div class="marquee-content"
|
|
60
|
-
data-mc-duration="60"
|
|
61
|
-
data-mc-direction="ltr"
|
|
62
|
-
role="marquee">
|
|
63
|
-
<ul>
|
|
64
|
-
<li><span class="font anton">Monarch</span></li>
|
|
65
|
-
<li><span class="font pt">Benassi</span></li>
|
|
66
|
-
<li><span class="font lobster">Air Max</span></li>
|
|
67
|
-
<li><span class="font prompt">Cortez</span></li>
|
|
68
|
-
<li><span class="font anton">Jordan</span></li>
|
|
69
|
-
<li><span class="font pt">Presto</span></li>
|
|
70
|
-
<li><span class="font prompt">Tempo</span></li>
|
|
71
|
-
<li><span class="font anton">Vomero</span></li>
|
|
72
|
-
<li><span class="font pt">Pegasus</span></li>
|
|
73
|
-
</ul>
|
|
74
|
-
</div>
|
|
75
|
-
</section>
|
|
76
|
-
<section class="data-code">
|
|
77
|
-
<strong>data-mc-duration="60" data-mc-direction="auto"</strong>
|
|
78
|
-
<p><code>data-mc-direction="auto"</code> — automatically changes the scrolling direction of the component when scrolling the page</p>
|
|
79
|
-
</section>
|
|
80
|
-
<section class="example-3">
|
|
81
|
-
<div class="marquee-content"
|
|
82
|
-
data-mc-duration="60"
|
|
83
|
-
data-mc-direction="auto"
|
|
84
|
-
role="marquee">
|
|
85
|
-
<ul class="font lobster">
|
|
86
|
-
<li>Monarch</li>
|
|
87
|
-
<li>Benassi</li>
|
|
88
|
-
<li>Air Max</li>
|
|
89
|
-
<li>Cortez</li>
|
|
90
|
-
<li>Jordan</li>
|
|
91
|
-
<li>Presto</li>
|
|
92
|
-
<li>Tempo</li>
|
|
93
|
-
<li>Vomero</li>
|
|
94
|
-
<li>Pegasus</li>
|
|
95
|
-
</ul>
|
|
96
|
-
</div>
|
|
97
|
-
</section>
|
|
98
|
-
<section class="data-code">
|
|
99
|
-
<strong>data-mc-duration="60" data-mc-skew="-3"</strong>
|
|
100
|
-
<p><code>data-mc-skew="-3"</code> — transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value)</p>
|
|
101
|
-
</section>
|
|
102
|
-
<section class="example-4">
|
|
103
|
-
<div class="marquee-content"
|
|
104
|
-
data-mc-duration="60"
|
|
105
|
-
data-mc-skew="-3"
|
|
106
|
-
role="marquee">
|
|
107
|
-
<ul class="font pt">
|
|
108
|
-
<li>Monarch</li>
|
|
109
|
-
<li>Benassi</li>
|
|
110
|
-
<li>Air Max</li>
|
|
111
|
-
<li>Cortez</li>
|
|
112
|
-
<li>Jordan</li>
|
|
113
|
-
<li>Presto</li>
|
|
114
|
-
<li>Tempo</li>
|
|
115
|
-
<li>Vomero</li>
|
|
116
|
-
<li>Pegasus</li>
|
|
117
|
-
</ul>
|
|
118
|
-
</div>
|
|
119
|
-
</section>
|
|
120
|
-
<section class="data-code">
|
|
121
|
-
<strong>data-mc-duration="5" data-mc-max="992"</strong>
|
|
122
|
-
<p><code>data-mc-max="992"</code> — sets the maximum screen width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared)</p>
|
|
123
|
-
</section>
|
|
124
|
-
<section class="example-6">
|
|
125
|
-
<div class="marquee-content"
|
|
126
|
-
data-mc-duration="5"
|
|
127
|
-
data-mc-max="992"
|
|
128
|
-
role="marquee">
|
|
129
|
-
<ul class="font pt">
|
|
130
|
-
<li>Jordan</li>
|
|
131
|
-
</ul>
|
|
132
|
-
</div>
|
|
133
|
-
</section>
|
|
134
|
-
<section class="data-code">
|
|
135
|
-
<strong>data-mc-duration="5" data-mc-min="992"</strong>
|
|
136
|
-
<p><code>data-mc-min="992"</code> — sets the minimum screen width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared)</p>
|
|
137
|
-
</section>
|
|
138
|
-
<section class="example-5">
|
|
139
|
-
<div class="marquee-content"
|
|
140
|
-
data-mc-duration="5"
|
|
141
|
-
data-mc-min="992"
|
|
142
|
-
role="marquee">
|
|
143
|
-
<ul class="font pt">
|
|
144
|
-
<li>Cortez</li>
|
|
145
|
-
</ul>
|
|
146
|
-
</div>
|
|
147
|
-
</section>
|
|
148
|
-
<script src="js/marquee-content.min.js"></script>
|
|
149
|
-
</body>
|
|
150
|
-
</html>
|