marquee-content 1.0.0 → 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 +16 -15
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.
|
|
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
|
}
|
|
@@ -4,7 +4,7 @@ export class MarqueeContent extends HTMLElement {
|
|
|
4
4
|
|
|
5
5
|
this.mm = gsap.matchMedia()
|
|
6
6
|
this.tl = gsap.timeline()
|
|
7
|
-
this.
|
|
7
|
+
this.dur = this.dataset.mcDuration || 20
|
|
8
8
|
this.skew = this.dataset.mcSkew
|
|
9
9
|
this.max = this.dataset.mcMax
|
|
10
10
|
this.min = this.dataset.mcMin
|
|
@@ -43,17 +43,17 @@ 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
|
-
return () => {
|
|
54
|
+
return () => {
|
|
55
|
+
removingClones()
|
|
56
|
+
}
|
|
57
57
|
})
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -90,7 +90,7 @@ export class MarqueeContent extends HTMLElement {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
this.tl.to(this.children, {
|
|
93
|
-
duration: this.
|
|
93
|
+
duration: this.dur,
|
|
94
94
|
x: '-100%',
|
|
95
95
|
ease: 'none',
|
|
96
96
|
repeat: -1
|
|
@@ -142,10 +142,11 @@ export class MarqueeContent extends HTMLElement {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
resizing() {
|
|
145
|
-
const
|
|
145
|
+
const resetAnimation = () => {
|
|
146
146
|
this.mm.add(this.breakpoint, () => {
|
|
147
147
|
this.tl.kill()
|
|
148
148
|
this.tl = null
|
|
149
|
+
|
|
149
150
|
gsap.set(this.children, { clearProps: true })
|
|
150
151
|
|
|
151
152
|
this.cloning()
|
|
@@ -156,16 +157,16 @@ export class MarqueeContent extends HTMLElement {
|
|
|
156
157
|
this.mm.add('(any-pointer: coarse)', () => {
|
|
157
158
|
let portrait = window.matchMedia('(orientation: portrait)')
|
|
158
159
|
|
|
159
|
-
portrait.addEventListener('change', (e) => {
|
|
160
|
+
portrait.addEventListener('change', this.debounce((e) => {
|
|
160
161
|
if(!e.matches) {
|
|
161
|
-
|
|
162
|
+
resetAnimation()
|
|
162
163
|
}
|
|
163
|
-
})
|
|
164
|
+
}, 250))
|
|
164
165
|
})
|
|
165
166
|
|
|
166
167
|
this.mm.add('(any-pointer: fine)', () => {
|
|
167
168
|
window.addEventListener('resize', this.debounce(() => {
|
|
168
|
-
|
|
169
|
+
resetAnimation()
|
|
169
170
|
}, 250))
|
|
170
171
|
})
|
|
171
172
|
}
|