marquee-content 0.0.8 → 1.0.0
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 +1 -1
- package/dist/index.html +15 -11
- package/dist/js/marquee-content.min.js +1 -1
- package/package.json +1 -1
- package/src/index.html +15 -11
- package/src/js/marquee-content.js +13 -14
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/ux-ui-pro/marquee-content)
|
|
8
8
|
[](https://www.npmjs.org/package/marquee-content)
|
|
9
9
|
|
|
10
|
-
<sup><a href="https://bundlephobia.com/package/marquee-content
|
|
10
|
+
<sup><a href="https://bundlephobia.com/package/marquee-content">1Kb gzipped</a></sup>
|
|
11
11
|
|
|
12
12
|
<h3><a href="https://ux-ui-pro.github.io/marquee-content/dist/">Demo</a></h3>
|
|
13
13
|
|
package/dist/index.html
CHANGED
|
@@ -25,12 +25,19 @@
|
|
|
25
25
|
role="marquee">
|
|
26
26
|
<ul class="font alkatra">
|
|
27
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>
|
|
28
35
|
</ul>
|
|
29
36
|
</marquee-content>
|
|
30
37
|
</section>
|
|
31
38
|
<section class="example-7">
|
|
32
39
|
<marquee-content
|
|
33
|
-
data-mc-duration="
|
|
40
|
+
data-mc-duration="20"
|
|
34
41
|
role="marquee">
|
|
35
42
|
<ul>
|
|
36
43
|
<li><img src="//fastly.picsum.photos/id/634/180/100.jpg?hmac=qB-PFAiiEVuXFwVxRbYUzImrQ4RZ2np6oWeK-XHPnXk" alt></li>
|
|
@@ -56,7 +63,6 @@
|
|
|
56
63
|
<li><span class="font prompt">Cortez</span></li>
|
|
57
64
|
<li><span class="font anton">Jordan</span></li>
|
|
58
65
|
<li><span class="font pt">Presto</span></li>
|
|
59
|
-
<li><span class="font lobster">Roshe</span></li>
|
|
60
66
|
<li><span class="font prompt">Tempo</span></li>
|
|
61
67
|
<li><span class="font anton">Vomero</span></li>
|
|
62
68
|
<li><span class="font pt">Pegasus</span></li>
|
|
@@ -79,7 +85,6 @@
|
|
|
79
85
|
<li>Cortez</li>
|
|
80
86
|
<li>Jordan</li>
|
|
81
87
|
<li>Presto</li>
|
|
82
|
-
<li>Roshe</li>
|
|
83
88
|
<li>Tempo</li>
|
|
84
89
|
<li>Vomero</li>
|
|
85
90
|
<li>Pegasus</li>
|
|
@@ -102,7 +107,6 @@
|
|
|
102
107
|
<li>Cortez</li>
|
|
103
108
|
<li>Jordan</li>
|
|
104
109
|
<li>Presto</li>
|
|
105
|
-
<li>Roshe</li>
|
|
106
110
|
<li>Tempo</li>
|
|
107
111
|
<li>Vomero</li>
|
|
108
112
|
<li>Pegasus</li>
|
|
@@ -110,13 +114,13 @@
|
|
|
110
114
|
</marquee-content>
|
|
111
115
|
</section>
|
|
112
116
|
<section class="data-code">
|
|
113
|
-
<strong>data-mc-duration="5" data-mc-min="
|
|
114
|
-
<p><code>data-mc-min="
|
|
117
|
+
<strong>data-mc-duration="5" data-mc-min="992"</strong>
|
|
118
|
+
<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>
|
|
115
119
|
</section>
|
|
116
120
|
<section class="example-5">
|
|
117
121
|
<marquee-content
|
|
118
122
|
data-mc-duration="5"
|
|
119
|
-
data-mc-min="
|
|
123
|
+
data-mc-min="992"
|
|
120
124
|
role="marquee">
|
|
121
125
|
<ul class="font pt">
|
|
122
126
|
<li>Jordan</li>
|
|
@@ -124,16 +128,16 @@
|
|
|
124
128
|
</marquee-content>
|
|
125
129
|
</section>
|
|
126
130
|
<section class="data-code">
|
|
127
|
-
<strong>data-mc-duration="5" data-mc-max="
|
|
128
|
-
<p><code>data-mc-max="
|
|
131
|
+
<strong>data-mc-duration="5" data-mc-max="992"</strong>
|
|
132
|
+
<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>
|
|
129
133
|
</section>
|
|
130
134
|
<section class="example-6">
|
|
131
135
|
<marquee-content
|
|
132
136
|
data-mc-duration="5"
|
|
133
|
-
data-mc-max="
|
|
137
|
+
data-mc-max="992"
|
|
134
138
|
role="marquee">
|
|
135
139
|
<ul class="font pt">
|
|
136
|
-
<li>
|
|
140
|
+
<li>Presto</li>
|
|
137
141
|
</ul>
|
|
138
142
|
</marquee-content>
|
|
139
143
|
</section>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.duration=this.dataset.mcDuration||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=""}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+3).toFixed(0);for(let e=1;e<t;e++){let t=this.firstElementChild,e=t.cloneNode(!0);t.parentNode.append(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.duration,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(){const t=()=>{this.mm.add(this.breakpoint,(()=>{this.tl.kill(),this.tl=null,gsap.set(this.children,{clearProps:!0}),this.cloning(),this.marquee()}))};
|
|
1
|
+
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.duration=this.dataset.mcDuration||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=""}cloning(){const t=()=>{for(;this.children.length>1;)this.removeChild(this.lastChild)};t(),this.mm.add(this.breakpoint,(()=>{if(this.hasChildNodes()){let t=(this.clientWidth/this.firstElementChild.clientWidth+3).toFixed(0);for(let e=1;e<t;e++){let t=this.firstElementChild,e=t.cloneNode(!0);t.parentNode.append(e)}}return()=>{t()}}))}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.duration,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(){const t=()=>{this.mm.add(this.breakpoint,(()=>{this.tl.kill(),this.tl=null,gsap.set(this.children,{clearProps:!0}),this.cloning(),this.marquee()}))};this.mm.add("(any-pointer: coarse)",(()=>{window.matchMedia("(orientation: portrait)").addEventListener("change",(e=>{e.matches||t()}))})),this.mm.add("(any-pointer: fine)",(()=>{window.addEventListener("resize",this.debounce((()=>{t()}),250))}))}}customElements.get("marquee-content")||customElements.define("marquee-content",t),new t})();
|
package/package.json
CHANGED
package/src/index.html
CHANGED
|
@@ -25,12 +25,19 @@
|
|
|
25
25
|
role="marquee">
|
|
26
26
|
<ul class="font alkatra">
|
|
27
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>
|
|
28
35
|
</ul>
|
|
29
36
|
</marquee-content>
|
|
30
37
|
</section>
|
|
31
38
|
<section class="example-7">
|
|
32
39
|
<marquee-content
|
|
33
|
-
data-mc-duration="
|
|
40
|
+
data-mc-duration="20"
|
|
34
41
|
role="marquee">
|
|
35
42
|
<ul>
|
|
36
43
|
<li><img src="//fastly.picsum.photos/id/634/180/100.jpg?hmac=qB-PFAiiEVuXFwVxRbYUzImrQ4RZ2np6oWeK-XHPnXk" alt></li>
|
|
@@ -56,7 +63,6 @@
|
|
|
56
63
|
<li><span class="font prompt">Cortez</span></li>
|
|
57
64
|
<li><span class="font anton">Jordan</span></li>
|
|
58
65
|
<li><span class="font pt">Presto</span></li>
|
|
59
|
-
<li><span class="font lobster">Roshe</span></li>
|
|
60
66
|
<li><span class="font prompt">Tempo</span></li>
|
|
61
67
|
<li><span class="font anton">Vomero</span></li>
|
|
62
68
|
<li><span class="font pt">Pegasus</span></li>
|
|
@@ -79,7 +85,6 @@
|
|
|
79
85
|
<li>Cortez</li>
|
|
80
86
|
<li>Jordan</li>
|
|
81
87
|
<li>Presto</li>
|
|
82
|
-
<li>Roshe</li>
|
|
83
88
|
<li>Tempo</li>
|
|
84
89
|
<li>Vomero</li>
|
|
85
90
|
<li>Pegasus</li>
|
|
@@ -102,7 +107,6 @@
|
|
|
102
107
|
<li>Cortez</li>
|
|
103
108
|
<li>Jordan</li>
|
|
104
109
|
<li>Presto</li>
|
|
105
|
-
<li>Roshe</li>
|
|
106
110
|
<li>Tempo</li>
|
|
107
111
|
<li>Vomero</li>
|
|
108
112
|
<li>Pegasus</li>
|
|
@@ -110,13 +114,13 @@
|
|
|
110
114
|
</marquee-content>
|
|
111
115
|
</section>
|
|
112
116
|
<section class="data-code">
|
|
113
|
-
<strong>data-mc-duration="5" data-mc-min="
|
|
114
|
-
<p><code>data-mc-min="
|
|
117
|
+
<strong>data-mc-duration="5" data-mc-min="992"</strong>
|
|
118
|
+
<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>
|
|
115
119
|
</section>
|
|
116
120
|
<section class="example-5">
|
|
117
121
|
<marquee-content
|
|
118
122
|
data-mc-duration="5"
|
|
119
|
-
data-mc-min="
|
|
123
|
+
data-mc-min="992"
|
|
120
124
|
role="marquee">
|
|
121
125
|
<ul class="font pt">
|
|
122
126
|
<li>Jordan</li>
|
|
@@ -124,16 +128,16 @@
|
|
|
124
128
|
</marquee-content>
|
|
125
129
|
</section>
|
|
126
130
|
<section class="data-code">
|
|
127
|
-
<strong>data-mc-duration="5" data-mc-max="
|
|
128
|
-
<p><code>data-mc-max="
|
|
131
|
+
<strong>data-mc-duration="5" data-mc-max="992"</strong>
|
|
132
|
+
<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>
|
|
129
133
|
</section>
|
|
130
134
|
<section class="example-6">
|
|
131
135
|
<marquee-content
|
|
132
136
|
data-mc-duration="5"
|
|
133
|
-
data-mc-max="
|
|
137
|
+
data-mc-max="992"
|
|
134
138
|
role="marquee">
|
|
135
139
|
<ul class="font pt">
|
|
136
|
-
<li>
|
|
140
|
+
<li>Presto</li>
|
|
137
141
|
</ul>
|
|
138
142
|
</marquee-content>
|
|
139
143
|
</section>
|
|
@@ -34,10 +34,14 @@ export class MarqueeContent extends HTMLElement {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
cloning() {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const removingClones = () => {
|
|
38
|
+
while (this.children.length > 1) {
|
|
39
|
+
this.removeChild(this.lastChild)
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
removingClones()
|
|
44
|
+
|
|
41
45
|
this.mm.add(this.breakpoint, () => {
|
|
42
46
|
if (this.hasChildNodes()) {
|
|
43
47
|
let requiredQuantity = (this.clientWidth / this.firstElementChild.clientWidth + 3).toFixed(0)
|
|
@@ -48,6 +52,8 @@ export class MarqueeContent extends HTMLElement {
|
|
|
48
52
|
item.parentNode.append(clone)
|
|
49
53
|
}
|
|
50
54
|
}
|
|
55
|
+
|
|
56
|
+
return () => { removingClones() }
|
|
51
57
|
})
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -147,16 +153,7 @@ export class MarqueeContent extends HTMLElement {
|
|
|
147
153
|
})
|
|
148
154
|
}
|
|
149
155
|
|
|
150
|
-
|
|
151
|
-
navigator.userAgent.match(/Android/i) ||
|
|
152
|
-
navigator.userAgent.match(/webOS/i) ||
|
|
153
|
-
navigator.userAgent.match(/iPhone/i) ||
|
|
154
|
-
navigator.userAgent.match(/iPad/i) ||
|
|
155
|
-
navigator.userAgent.match(/iPod/i) ||
|
|
156
|
-
navigator.userAgent.match(/BlackBerry/i) ||
|
|
157
|
-
navigator.userAgent.match(/Windows Phone/i)
|
|
158
|
-
|
|
159
|
-
if (userAgents) {
|
|
156
|
+
this.mm.add('(any-pointer: coarse)', () => {
|
|
160
157
|
let portrait = window.matchMedia('(orientation: portrait)')
|
|
161
158
|
|
|
162
159
|
portrait.addEventListener('change', (e) => {
|
|
@@ -164,11 +161,13 @@ export class MarqueeContent extends HTMLElement {
|
|
|
164
161
|
resetAmin()
|
|
165
162
|
}
|
|
166
163
|
})
|
|
167
|
-
}
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
this.mm.add('(any-pointer: fine)', () => {
|
|
168
167
|
window.addEventListener('resize', this.debounce(() => {
|
|
169
168
|
resetAmin()
|
|
170
169
|
}, 250))
|
|
171
|
-
}
|
|
170
|
+
})
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
173
|
|