marquee-content 1.0.1 → 1.0.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 +6 -1
- package/dist/js/marquee-content.min.js +1 -1
- package/package.json +2 -7
- package/src/js/marquee-content.js +9 -9
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
|
|
|
@@ -48,7 +53,7 @@ import { MarqueeContent } from 'marquee-content'
|
|
|
48
53
|
|
|
49
54
|
### Settings
|
|
50
55
|
|
|
51
|
-
| data
|
|
56
|
+
| data-* | Default | Description |
|
|
52
57
|
| --- | --- | --- |
|
|
53
58
|
| `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
|
|
54
59
|
| `data-mc-direction` | `rtl` | `rtl` — default value, no need to specify.<br>`ltr` — changes the scroll direction from left to right.<br>`auto` — automatically changes the direction of the animation when scrolling the page. |
|
|
@@ -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,(()=>{
|
|
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,(()=>{let e=(this.clientWidth/this.firstElementChild.clientWidth+3).toFixed(0);for(let t=1;t<e;t++){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.0.2",
|
|
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,14 +43,12 @@ export class MarqueeContent extends HTMLElement {
|
|
|
43
43
|
removingClones()
|
|
44
44
|
|
|
45
45
|
this.mm.add(this.breakpoint, () => {
|
|
46
|
-
|
|
47
|
-
let requiredQuantity = (this.clientWidth / this.firstElementChild.clientWidth + 3).toFixed(0)
|
|
46
|
+
let requiredQuantity = (this.clientWidth / this.firstElementChild.clientWidth + 3).toFixed(0)
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
for (let i = 1; i < requiredQuantity; i++) {
|
|
49
|
+
let item = this.firstElementChild
|
|
50
|
+
let clone = item.cloneNode(true)
|
|
51
|
+
item.parentNode.append(clone)
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
return () => {
|
|
@@ -148,7 +146,9 @@ export class MarqueeContent extends HTMLElement {
|
|
|
148
146
|
this.mm.add(this.breakpoint, () => {
|
|
149
147
|
this.tl.kill()
|
|
150
148
|
this.tl = null
|
|
149
|
+
|
|
151
150
|
gsap.set(this.children, { clearProps: true })
|
|
151
|
+
|
|
152
152
|
this.cloning()
|
|
153
153
|
this.marquee()
|
|
154
154
|
})
|
|
@@ -157,11 +157,11 @@ export class MarqueeContent extends HTMLElement {
|
|
|
157
157
|
this.mm.add('(any-pointer: coarse)', () => {
|
|
158
158
|
let portrait = window.matchMedia('(orientation: portrait)')
|
|
159
159
|
|
|
160
|
-
portrait.addEventListener('change', (e) => {
|
|
160
|
+
portrait.addEventListener('change', this.debounce((e) => {
|
|
161
161
|
if(!e.matches) {
|
|
162
162
|
resetAnimation()
|
|
163
163
|
}
|
|
164
|
-
})
|
|
164
|
+
}, 250))
|
|
165
165
|
})
|
|
166
166
|
|
|
167
167
|
this.mm.add('(any-pointer: fine)', () => {
|