marquee-content 1.0.1 → 1.1.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 +5 -0
- package/dist/js/marquee-content.min.js +1 -1
- package/package.json +2 -7
- package/src/js/marquee-content.js +7 -5
package/README.md
CHANGED
|
@@ -27,7 +27,12 @@ $ npm i marquee-content
|
|
|
27
27
|
|
|
28
28
|
### Import
|
|
29
29
|
```javascript
|
|
30
|
+
import { gsap } from 'gsap'
|
|
31
|
+
import { ScrollTrigger } from 'gsap/ScrollTrigger'
|
|
32
|
+
|
|
30
33
|
import { MarqueeContent } from 'marquee-content'
|
|
34
|
+
|
|
35
|
+
gsap.registerPlugin(ScrollTrigger)
|
|
31
36
|
```
|
|
32
37
|
<br>
|
|
33
38
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.dur=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.
|
|
1
|
+
(()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.dur=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.children.length>0){let t=Math.ceil(this.clientWidth/this.children[0].scrollWidth);for(let e=1;e<t+2;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.dur,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",this.debounce((e=>{e.matches||t()}),250))})),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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marquee-content",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Marquee content with GSAP",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,11 +37,6 @@
|
|
|
37
37
|
"webpack-stream": "^7.0.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
|
-
"
|
|
41
|
-
"fit",
|
|
42
|
-
"size",
|
|
43
|
-
"width",
|
|
44
|
-
"font",
|
|
45
|
-
"responsive"
|
|
40
|
+
"marquee"
|
|
46
41
|
]
|
|
47
42
|
}
|
|
@@ -43,10 +43,10 @@ export class MarqueeContent extends HTMLElement {
|
|
|
43
43
|
removingClones()
|
|
44
44
|
|
|
45
45
|
this.mm.add(this.breakpoint, () => {
|
|
46
|
-
if (this.
|
|
47
|
-
let requiredQuantity = (this.clientWidth / this.
|
|
46
|
+
if (this.children.length > 0) {
|
|
47
|
+
let requiredQuantity = Math.ceil(this.clientWidth / this.children[0].scrollWidth)
|
|
48
48
|
|
|
49
|
-
for (let i = 1; i < requiredQuantity; i++) {
|
|
49
|
+
for (let i = 1; i < (requiredQuantity) + 2; i++) {
|
|
50
50
|
let item = this.firstElementChild
|
|
51
51
|
let clone = item.cloneNode(true)
|
|
52
52
|
item.parentNode.append(clone)
|
|
@@ -148,7 +148,9 @@ export class MarqueeContent extends HTMLElement {
|
|
|
148
148
|
this.mm.add(this.breakpoint, () => {
|
|
149
149
|
this.tl.kill()
|
|
150
150
|
this.tl = null
|
|
151
|
+
|
|
151
152
|
gsap.set(this.children, { clearProps: true })
|
|
153
|
+
|
|
152
154
|
this.cloning()
|
|
153
155
|
this.marquee()
|
|
154
156
|
})
|
|
@@ -157,11 +159,11 @@ export class MarqueeContent extends HTMLElement {
|
|
|
157
159
|
this.mm.add('(any-pointer: coarse)', () => {
|
|
158
160
|
let portrait = window.matchMedia('(orientation: portrait)')
|
|
159
161
|
|
|
160
|
-
portrait.addEventListener('change', (e) => {
|
|
162
|
+
portrait.addEventListener('change', this.debounce((e) => {
|
|
161
163
|
if(!e.matches) {
|
|
162
164
|
resetAnimation()
|
|
163
165
|
}
|
|
164
|
-
})
|
|
166
|
+
}, 250))
|
|
165
167
|
})
|
|
166
168
|
|
|
167
169
|
this.mm.add('(any-pointer: fine)', () => {
|