marquee-content 0.0.3 → 0.0.6
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 +6 -6
- package/dist/index.html +7 -13
- package/dist/js/marquee-content.min.js +1 -1
- package/package.json +1 -1
- package/src/index.html +7 -13
- package/src/js/marquee-content.js +38 -15
package/README.md
CHANGED
|
@@ -49,14 +49,14 @@ import { MarqueeContent } from 'marquee-content'
|
|
|
49
49
|
|
|
50
50
|
### Settings
|
|
51
51
|
|
|
52
|
-
| data- | Default | Description |
|
|
52
|
+
| data- | Default | Description |
|
|
53
53
|
| --- | --- | --- |
|
|
54
|
-
| `data-mc-clone` |
|
|
54
|
+
| `data-mc-clone` | `null` | Clones the content of the component the specified number of times. |
|
|
55
55
|
| `data-mc-speed` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
|
|
56
|
-
| `data-mc-direction` | `rtl` | `ltr` changes the scroll direction from left to right
|
|
57
|
-
| `data-mc-skew` |
|
|
58
|
-
| `data-mc-min` |
|
|
59
|
-
| `data-mc-max` |
|
|
56
|
+
| `data-mc-direction` | `rtl` | `ltr` — changes the scroll direction from left to right.<br>`auto` — automatically changes the scrolling direction of the component when scrolling the page. |
|
|
57
|
+
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value). |
|
|
58
|
+
| `data-mc-min` | `null` | Sets the minimum 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). |
|
|
59
|
+
| `data-mc-max` | `null` | Sets the maximum 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). |
|
|
60
60
|
|
|
61
61
|
<br>
|
|
62
62
|
|
package/dist/index.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
body {
|
|
20
|
-
margin:
|
|
20
|
+
margin: 200px 0 500px;
|
|
21
21
|
font-feature-settings: "kern" 1,"liga" 0;
|
|
22
22
|
font-size: 1.6rem;
|
|
23
23
|
font-weight: 400;
|
|
@@ -156,12 +156,11 @@
|
|
|
156
156
|
</head>
|
|
157
157
|
<body>
|
|
158
158
|
<section class="data-code">
|
|
159
|
-
<strong>data-mc-
|
|
159
|
+
<strong>data-mc-speed="50"</strong>
|
|
160
160
|
<p>The basic version, with scrolling content from right to left (in this example, 3 clones of scrollable content are added, scrolling lasts 50 seconds)</p>
|
|
161
161
|
</section>
|
|
162
162
|
<section class="example-1">
|
|
163
163
|
<marquee-content
|
|
164
|
-
data-mc-clone="3"
|
|
165
164
|
data-mc-speed="50"
|
|
166
165
|
role="marquee">
|
|
167
166
|
<ul class="font alkatra">
|
|
@@ -179,12 +178,11 @@
|
|
|
179
178
|
</marquee-content>
|
|
180
179
|
</section>
|
|
181
180
|
<section class="data-code">
|
|
182
|
-
<strong>data-mc-
|
|
181
|
+
<strong>data-mc-speed="70" data-mc-direction="ltr"</strong>
|
|
183
182
|
<p><code>data-mc-direction="ltr"</code> — changes the scroll direction from left to right</p>
|
|
184
183
|
</section>
|
|
185
184
|
<section class="example-2">
|
|
186
185
|
<marquee-content
|
|
187
|
-
data-mc-clone="3"
|
|
188
186
|
data-mc-speed="70"
|
|
189
187
|
data-mc-direction="ltr"
|
|
190
188
|
role="marquee">
|
|
@@ -203,12 +201,11 @@
|
|
|
203
201
|
</marquee-content>
|
|
204
202
|
</section>
|
|
205
203
|
<section class="data-code">
|
|
206
|
-
<strong>data-mc-
|
|
204
|
+
<strong>data-mc-speed="60" data-mc-direction="auto"</strong>
|
|
207
205
|
<p><code>data-mc-direction="auto"</code> — automatically changes the scrolling direction of the component when scrolling the page</p>
|
|
208
206
|
</section>
|
|
209
207
|
<section class="example-3">
|
|
210
208
|
<marquee-content
|
|
211
|
-
data-mc-clone="3"
|
|
212
209
|
data-mc-speed="60"
|
|
213
210
|
data-mc-direction="auto"
|
|
214
211
|
role="marquee">
|
|
@@ -227,12 +224,11 @@
|
|
|
227
224
|
</marquee-content>
|
|
228
225
|
</section>
|
|
229
226
|
<section class="data-code">
|
|
230
|
-
<strong>data-mc-
|
|
227
|
+
<strong>data-mc-speed="60" data-mc-skew="-3"</strong>
|
|
231
228
|
<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>
|
|
232
229
|
</section>
|
|
233
230
|
<section class="example-4">
|
|
234
231
|
<marquee-content
|
|
235
|
-
data-mc-clone="3"
|
|
236
232
|
data-mc-speed="60"
|
|
237
233
|
data-mc-skew="-3"
|
|
238
234
|
role="marquee">
|
|
@@ -251,12 +247,11 @@
|
|
|
251
247
|
</marquee-content>
|
|
252
248
|
</section>
|
|
253
249
|
<section class="data-code">
|
|
254
|
-
<strong>data-mc-
|
|
250
|
+
<strong>data-mc-speed="60" data-mc-min="1200"</strong>
|
|
255
251
|
<p><code>data-mc-min="1200"</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>
|
|
256
252
|
</section>
|
|
257
253
|
<section class="example-5">
|
|
258
254
|
<marquee-content
|
|
259
|
-
data-mc-clone="3"
|
|
260
255
|
data-mc-speed="60"
|
|
261
256
|
data-mc-min="1200"
|
|
262
257
|
role="marquee">
|
|
@@ -275,12 +270,11 @@
|
|
|
275
270
|
</marquee-content>
|
|
276
271
|
</section>
|
|
277
272
|
<section class="data-code">
|
|
278
|
-
<strong>data-mc-
|
|
273
|
+
<strong>data-mc-speed="60" data-mc-max="1200"</strong>
|
|
279
274
|
<p><code>data-mc-max="1200"</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>
|
|
280
275
|
</section>
|
|
281
276
|
<section class="example-6">
|
|
282
277
|
<marquee-content
|
|
283
|
-
data-mc-clone="3"
|
|
284
278
|
data-mc-speed="60"
|
|
285
279
|
data-mc-max="1200"
|
|
286
280
|
role="marquee">
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.speed=this.dataset.mcSpeed||20,this.
|
|
1
|
+
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.speed=this.dataset.mcSpeed||20,this.skew=this.dataset.mcSkew,this.max=this.dataset.mcMax,this.min=this.dataset.mcMin,this.dir=this.dataset.mcDirection,this.breakpoints(),this.cloning(),this.skewed(),this.marquee(),this.scrollReverse(),this.debounce(),this.resizing()}breakpoints(){this.max||this.min?(this.max&&(this.breakpoint=`(max-width: ${this.max-.02}px)`),this.min&&(this.breakpoint=`(min-width: ${this.min}px)`)):this.breakpoint="(min-width: 100vw)"}cloning(){for(;this.children.length>1;)this.removeChild(this.lastChild);this.mm.add(this.breakpoint,(()=>{if(this.hasChildNodes()){let t=(this.clientWidth/this.firstElementChild.clientWidth+2).toFixed(0);for(let e=0;e<t;e++){let t=this.firstElementChild,e=t.cloneNode(!0);t.after(e)}}}))}skewed(){this.skew&&this.mm.add(this.breakpoint,(()=>{let t=this.skew<0?-1*this.skew:this.skew;return this.style.transformOrigin="center center",this.style.transform=`skew(0deg, ${this.skew}deg)`,this.style.minHeight=`calc(${1.25*t}vh + ${1.25*t}vw)`,()=>{this.style.removeProperty("transform-origin"),this.style.removeProperty("transform"),this.style.removeProperty("min-height")}}))}marquee(){this.mm.add(this.breakpoint,(()=>{this.tl=gsap.timeline(),gsap.config({nullTargetWarn:!1}),this.tl.paused(!0),gsap.set(this.children,{"will-change":"transform"}),this.tl.to(this.children,{duration:this.speed,x:"-100%",ease:"none",repeat:-1}).timeScale("ltr"===this.dir?-1:1).totalProgress(.5),ScrollTrigger.create({trigger:this,start:"top bottom",end:"bottom top",onEnter:()=>this.tl.resume(),onLeave:()=>this.tl.pause(),onEnterBack:()=>this.tl.resume(),onLeaveBack:()=>this.tl.pause()})}))}scrollReverse(){"auto"===this.dir&&this.mm.add(this.breakpoint,(()=>{let t=0,e=1;window.addEventListener("scroll",(()=>{let i=window.pageYOffset>t?1:-1;i!==e&&(gsap.to(this.tl,{timeScale:i,overwrite:!0}),e=i),t=window.pageYOffset}))}))}debounce(t,e){let i;return(...s)=>{i&&clearTimeout(i),i=setTimeout((()=>t(...s)),e)}}resizing(){window.addEventListener("resize",this.debounce((()=>{this.tl.pause(),gsap.set(this.children,{clearProps:!0}),this.cloning(),this.marquee()}),250))}}customElements.get("marquee-content")||customElements.define("marquee-content",t),new t})();
|
package/package.json
CHANGED
package/src/index.html
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
body {
|
|
20
|
-
margin:
|
|
20
|
+
margin: 200px 0 500px;
|
|
21
21
|
font-feature-settings: "kern" 1,"liga" 0;
|
|
22
22
|
font-size: 1.6rem;
|
|
23
23
|
font-weight: 400;
|
|
@@ -156,12 +156,11 @@
|
|
|
156
156
|
</head>
|
|
157
157
|
<body>
|
|
158
158
|
<section class="data-code">
|
|
159
|
-
<strong>data-mc-
|
|
159
|
+
<strong>data-mc-speed="50"</strong>
|
|
160
160
|
<p>The basic version, with scrolling content from right to left (in this example, 3 clones of scrollable content are added, scrolling lasts 50 seconds)</p>
|
|
161
161
|
</section>
|
|
162
162
|
<section class="example-1">
|
|
163
163
|
<marquee-content
|
|
164
|
-
data-mc-clone="3"
|
|
165
164
|
data-mc-speed="50"
|
|
166
165
|
role="marquee">
|
|
167
166
|
<ul class="font alkatra">
|
|
@@ -179,12 +178,11 @@
|
|
|
179
178
|
</marquee-content>
|
|
180
179
|
</section>
|
|
181
180
|
<section class="data-code">
|
|
182
|
-
<strong>data-mc-
|
|
181
|
+
<strong>data-mc-speed="70" data-mc-direction="ltr"</strong>
|
|
183
182
|
<p><code>data-mc-direction="ltr"</code> — changes the scroll direction from left to right</p>
|
|
184
183
|
</section>
|
|
185
184
|
<section class="example-2">
|
|
186
185
|
<marquee-content
|
|
187
|
-
data-mc-clone="3"
|
|
188
186
|
data-mc-speed="70"
|
|
189
187
|
data-mc-direction="ltr"
|
|
190
188
|
role="marquee">
|
|
@@ -203,12 +201,11 @@
|
|
|
203
201
|
</marquee-content>
|
|
204
202
|
</section>
|
|
205
203
|
<section class="data-code">
|
|
206
|
-
<strong>data-mc-
|
|
204
|
+
<strong>data-mc-speed="60" data-mc-direction="auto"</strong>
|
|
207
205
|
<p><code>data-mc-direction="auto"</code> — automatically changes the scrolling direction of the component when scrolling the page</p>
|
|
208
206
|
</section>
|
|
209
207
|
<section class="example-3">
|
|
210
208
|
<marquee-content
|
|
211
|
-
data-mc-clone="3"
|
|
212
209
|
data-mc-speed="60"
|
|
213
210
|
data-mc-direction="auto"
|
|
214
211
|
role="marquee">
|
|
@@ -227,12 +224,11 @@
|
|
|
227
224
|
</marquee-content>
|
|
228
225
|
</section>
|
|
229
226
|
<section class="data-code">
|
|
230
|
-
<strong>data-mc-
|
|
227
|
+
<strong>data-mc-speed="60" data-mc-skew="-3"</strong>
|
|
231
228
|
<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>
|
|
232
229
|
</section>
|
|
233
230
|
<section class="example-4">
|
|
234
231
|
<marquee-content
|
|
235
|
-
data-mc-clone="3"
|
|
236
232
|
data-mc-speed="60"
|
|
237
233
|
data-mc-skew="-3"
|
|
238
234
|
role="marquee">
|
|
@@ -251,12 +247,11 @@
|
|
|
251
247
|
</marquee-content>
|
|
252
248
|
</section>
|
|
253
249
|
<section class="data-code">
|
|
254
|
-
<strong>data-mc-
|
|
250
|
+
<strong>data-mc-speed="60" data-mc-min="1200"</strong>
|
|
255
251
|
<p><code>data-mc-min="1200"</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>
|
|
256
252
|
</section>
|
|
257
253
|
<section class="example-5">
|
|
258
254
|
<marquee-content
|
|
259
|
-
data-mc-clone="3"
|
|
260
255
|
data-mc-speed="60"
|
|
261
256
|
data-mc-min="1200"
|
|
262
257
|
role="marquee">
|
|
@@ -275,12 +270,11 @@
|
|
|
275
270
|
</marquee-content>
|
|
276
271
|
</section>
|
|
277
272
|
<section class="data-code">
|
|
278
|
-
<strong>data-mc-
|
|
273
|
+
<strong>data-mc-speed="60" data-mc-max="1200"</strong>
|
|
279
274
|
<p><code>data-mc-max="1200"</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>
|
|
280
275
|
</section>
|
|
281
276
|
<section class="example-6">
|
|
282
277
|
<marquee-content
|
|
283
|
-
data-mc-clone="3"
|
|
284
278
|
data-mc-speed="60"
|
|
285
279
|
data-mc-max="1200"
|
|
286
280
|
role="marquee">
|
|
@@ -5,9 +5,7 @@ export class MarqueeContent extends HTMLElement {
|
|
|
5
5
|
this.mm = gsap.matchMedia()
|
|
6
6
|
this.tl = gsap.timeline()
|
|
7
7
|
this.speed = this.dataset.mcSpeed || 20
|
|
8
|
-
this.clone = this.dataset.mcClone
|
|
9
8
|
this.skew = this.dataset.mcSkew
|
|
10
|
-
this.abs = (this.skew < 0) ? this.skew * -1 : this.skew
|
|
11
9
|
this.max = this.dataset.mcMax
|
|
12
10
|
this.min = this.dataset.mcMin
|
|
13
11
|
this.dir = this.dataset.mcDirection
|
|
@@ -16,7 +14,9 @@ export class MarqueeContent extends HTMLElement {
|
|
|
16
14
|
this.cloning()
|
|
17
15
|
this.skewed()
|
|
18
16
|
this.marquee()
|
|
19
|
-
this.
|
|
17
|
+
this.scrollReverse()
|
|
18
|
+
this.debounce()
|
|
19
|
+
this.resizing()
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
breakpoints() {
|
|
@@ -34,18 +34,18 @@ export class MarqueeContent extends HTMLElement {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
cloning() {
|
|
37
|
-
|
|
37
|
+
while (this.children.length > 1) {
|
|
38
|
+
this.removeChild(this.lastChild)
|
|
39
|
+
}
|
|
38
40
|
|
|
39
41
|
this.mm.add(this.breakpoint, () => {
|
|
40
|
-
|
|
41
|
-
let
|
|
42
|
-
let clone = item.cloneNode(true)
|
|
43
|
-
item.after(clone)
|
|
44
|
-
}
|
|
42
|
+
if (this.hasChildNodes()) {
|
|
43
|
+
let requiredQuantity = (this.clientWidth / this.firstElementChild.clientWidth + 2).toFixed(0)
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
for (let i = 0; i < requiredQuantity; i++) {
|
|
46
|
+
let item = this.firstElementChild
|
|
47
|
+
let clone = item.cloneNode(true)
|
|
48
|
+
item.after(clone)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
})
|
|
@@ -55,20 +55,24 @@ export class MarqueeContent extends HTMLElement {
|
|
|
55
55
|
if(!this.skew) { return }
|
|
56
56
|
|
|
57
57
|
this.mm.add(this.breakpoint, () => {
|
|
58
|
-
|
|
58
|
+
let abs = (this.skew < 0) ? this.skew * -1 : this.skew
|
|
59
|
+
|
|
59
60
|
this.style.transformOrigin = `center center`
|
|
60
61
|
this.style.transform = `skew(0deg, ${this.skew}deg)`
|
|
62
|
+
this.style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
|
|
61
63
|
|
|
62
64
|
return () => {
|
|
63
|
-
this.style.removeProperty('min-height')
|
|
64
65
|
this.style.removeProperty('transform-origin')
|
|
65
66
|
this.style.removeProperty('transform')
|
|
67
|
+
this.style.removeProperty('min-height')
|
|
66
68
|
}
|
|
67
69
|
})
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
marquee() {
|
|
71
73
|
this.mm.add(this.breakpoint, () => {
|
|
74
|
+
this.tl = gsap.timeline()
|
|
75
|
+
|
|
72
76
|
gsap.config({
|
|
73
77
|
nullTargetWarn: false
|
|
74
78
|
})
|
|
@@ -98,7 +102,7 @@ export class MarqueeContent extends HTMLElement {
|
|
|
98
102
|
})
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
scrollReverse() {
|
|
102
106
|
if(this.dir !== 'auto') { return }
|
|
103
107
|
|
|
104
108
|
this.mm.add(this.breakpoint, () => {
|
|
@@ -121,6 +125,25 @@ export class MarqueeContent extends HTMLElement {
|
|
|
121
125
|
})
|
|
122
126
|
})
|
|
123
127
|
}
|
|
128
|
+
|
|
129
|
+
debounce(fn, delay) {
|
|
130
|
+
let timer
|
|
131
|
+
|
|
132
|
+
return (...args) => {
|
|
133
|
+
if (timer) clearTimeout(timer)
|
|
134
|
+
timer = setTimeout(() => fn(...args), delay)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
resizing() {
|
|
139
|
+
window.addEventListener('resize', this.debounce(() => {
|
|
140
|
+
this.tl.pause()
|
|
141
|
+
gsap.set(this.children, { clearProps: true })
|
|
142
|
+
|
|
143
|
+
this.cloning()
|
|
144
|
+
this.marquee()
|
|
145
|
+
}, 250))
|
|
146
|
+
}
|
|
124
147
|
}
|
|
125
148
|
|
|
126
149
|
customElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)
|