marquee-content 2.0.0 → 2.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 +3 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +5 -6
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +7 -9
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
[](https://github.com/ux-ui-pro/marquee-content)
|
|
10
10
|
[](https://www.npmjs.org/package/marquee-content)
|
|
11
11
|
|
|
12
|
+
<sup><a href="https://bundlephobia.com/package/marquee-content">1.3kB gzipped</a></sup>
|
|
12
13
|
<h3><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></h3>
|
|
13
14
|
|
|
14
15
|
</div>
|
|
@@ -29,7 +30,8 @@ $ npm i marquee-content
|
|
|
29
30
|
|
|
30
31
|
### Import
|
|
31
32
|
```javascript
|
|
32
|
-
import gsap from 'gsap'
|
|
33
|
+
import { gsap } from 'gsap'
|
|
34
|
+
import { ScrollTrigger } from 'gsap/ScrollTrigger'
|
|
33
35
|
import MarqueeContent from 'marquee-content'
|
|
34
36
|
|
|
35
37
|
gsap.registerPlugin(ScrollTrigger)
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
14
14
|
this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
15
15
|
this.MM = this.gsap.matchMedia();
|
|
16
16
|
this.breakpoint = this.dataset.mcMax ? `(max-width: ${this.dataset.mcMax - 0.02}px)` : this.dataset.mcMin ? `(min-width: ${this.dataset.mcMin}px)` : "";
|
|
17
|
-
this.
|
|
18
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.
|
|
17
|
+
this.update = this.update.bind(this);
|
|
18
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
19
19
|
this.resizeObserver.observe(this);
|
|
20
20
|
}
|
|
21
21
|
static registerGSAP(gsap) {
|
|
@@ -118,8 +118,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
118
118
|
passive: true
|
|
119
119
|
});
|
|
120
120
|
};
|
|
121
|
-
|
|
122
|
-
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
121
|
+
this.dataset.mcDirection === "ltr" ? ltrDirection() : this.dataset.mcDirection === "auto" && autoDirection();
|
|
123
122
|
return ()=>{
|
|
124
123
|
this.gsap.set(this.children, {
|
|
125
124
|
clearProps: true
|
|
@@ -127,7 +126,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
127
126
|
};
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
|
-
|
|
129
|
+
update() {
|
|
131
130
|
cancelAnimationFrame(this.af);
|
|
132
131
|
if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
|
|
133
132
|
this.cloning();
|
|
@@ -136,8 +135,8 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
136
135
|
}
|
|
137
136
|
connectedCallback() {
|
|
138
137
|
this.templates();
|
|
139
|
-
this.cloning();
|
|
140
138
|
this.skewed();
|
|
139
|
+
this.cloning();
|
|
141
140
|
this.animation();
|
|
142
141
|
}
|
|
143
142
|
disconnectedCallback() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,GAC9B,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG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tC;YAEA,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,QAAQ,iBACjC,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAS,eAC9B;YAEZ,OAAO,IAAM;gBACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAAE,YAAY,IAAI;gBAAC;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IAER;IAEA,oBAAoB;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,SAAS;IAClB;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC,EAAE;IAChC;AACJ;AAEA,eAAe,GAAG,CAAC,sBAAsB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.breakpoint = this.dataset.mcMax\n ? `(max-width: ${this.dataset.mcMax - 0.02}px)`\n : this.dataset.mcMin\n ? `(min-width: ${this.dataset.mcMin}px)`\n : ''\n\n this.update = this.update.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const wrapper = document.createElement('div')\n wrapper.classList.add('marquee-wrapper')\n\n const inner = document.createElement('div')\n inner.classList.add('marquee-inner')\n inner.style.display = 'inline-block'\n inner.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild)\n }\n\n wrapper.appendChild(inner)\n this.appendChild(wrapper)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n this.MM.add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'\n }\n })\n }\n\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause'\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let currentScroll = 0,\n scrollDirection = 1\n\n const handleScroll = () => {\n let orientation = (window.pageYOffset > currentScroll) ? 1 : -1\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true\n })\n\n scrollDirection = orientation\n }\n\n currentScroll = window.pageYOffset\n }\n\n addEventListener('scroll', () => {\n handleScroll()\n }, { capture: true, passive: true })\n }\n\n this.dataset.mcDirection === 'ltr' ? ltrDirection() :\n this.dataset.mcDirection === 'auto' ? autoDirection() :\n null\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n update() {\n cancelAnimationFrame(this.af)\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n }\n\n connectedCallback() {\n this.templates()\n this.skewed()\n this.cloning()\n this.animation()\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af)\n }\n}\n\ncustomElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -4,8 +4,8 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
4
4
|
this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
5
5
|
this.MM = this.gsap.matchMedia();
|
|
6
6
|
this.breakpoint = this.dataset.mcMax ? `(max-width: ${this.dataset.mcMax - 0.02}px)` : this.dataset.mcMin ? `(min-width: ${this.dataset.mcMin}px)` : "";
|
|
7
|
-
this.
|
|
8
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.
|
|
7
|
+
this.update = this.update.bind(this);
|
|
8
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
9
9
|
this.resizeObserver.observe(this);
|
|
10
10
|
}
|
|
11
11
|
static registerGSAP(gsap) {
|
|
@@ -108,8 +108,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
108
108
|
passive: true
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
|
-
|
|
112
|
-
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
111
|
+
this.dataset.mcDirection === "ltr" ? ltrDirection() : this.dataset.mcDirection === "auto" && autoDirection();
|
|
113
112
|
return ()=>{
|
|
114
113
|
this.gsap.set(this.children, {
|
|
115
114
|
clearProps: true
|
|
@@ -117,7 +116,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
117
116
|
};
|
|
118
117
|
});
|
|
119
118
|
}
|
|
120
|
-
|
|
119
|
+
update() {
|
|
121
120
|
cancelAnimationFrame(this.af);
|
|
122
121
|
if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
|
|
123
122
|
this.cloning();
|
|
@@ -126,8 +125,8 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
126
125
|
}
|
|
127
126
|
connectedCallback() {
|
|
128
127
|
this.templates();
|
|
129
|
-
this.cloning();
|
|
130
128
|
this.skewed();
|
|
129
|
+
this.cloning();
|
|
131
130
|
this.animation();
|
|
132
131
|
}
|
|
133
132
|
disconnectedCallback() {
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,GAC9B,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,GAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,GAClB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GACtC,EAAE;QAER,IAAI,CAAC,
|
|
1
|
+
{"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAA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AI,CAAC,iBAAiB,EACtB,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IAER;IAEA,oBAAoB;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,SAAS;IAClB;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC,EAAE;IAChC;AACJ;AAEA,eAAe,GAAG,CAAC,sBAAsB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.breakpoint = this.dataset.mcMax\n ? `(max-width: ${this.dataset.mcMax - 0.02}px)`\n : this.dataset.mcMin\n ? `(min-width: ${this.dataset.mcMin}px)`\n : ''\n\n this.update = this.update.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const wrapper = document.createElement('div')\n wrapper.classList.add('marquee-wrapper')\n\n const inner = document.createElement('div')\n inner.classList.add('marquee-inner')\n inner.style.display = 'inline-block'\n inner.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild)\n }\n\n wrapper.appendChild(inner)\n this.appendChild(wrapper)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n this.MM.add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'\n }\n })\n }\n\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause'\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let currentScroll = 0,\n scrollDirection = 1\n\n const handleScroll = () => {\n let orientation = (window.pageYOffset > currentScroll) ? 1 : -1\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true\n })\n\n scrollDirection = orientation\n }\n\n currentScroll = window.pageYOffset\n }\n\n addEventListener('scroll', () => {\n handleScroll()\n }, { capture: true, passive: true })\n }\n\n this.dataset.mcDirection === 'ltr' ? ltrDirection() :\n this.dataset.mcDirection === 'auto' ? autoDirection() :\n null\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n update() {\n cancelAnimationFrame(this.af)\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n }\n\n connectedCallback() {\n this.templates()\n this.skewed()\n this.cloning()\n this.animation()\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af)\n }\n}\n\ncustomElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,8 +10,8 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
10
10
|
? `(min-width: ${this.dataset.mcMin}px)`
|
|
11
11
|
: ''
|
|
12
12
|
|
|
13
|
-
this.
|
|
14
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.
|
|
13
|
+
this.update = this.update.bind(this)
|
|
14
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))
|
|
15
15
|
this.resizeObserver.observe(this)
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -143,11 +143,9 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
143
143
|
}, { capture: true, passive: true })
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
autoDirection()
|
|
150
|
-
}
|
|
146
|
+
this.dataset.mcDirection === 'ltr' ? ltrDirection() :
|
|
147
|
+
this.dataset.mcDirection === 'auto' ? autoDirection() :
|
|
148
|
+
null
|
|
151
149
|
|
|
152
150
|
return () => {
|
|
153
151
|
this.gsap.set(this.children, { clearProps: true })
|
|
@@ -155,7 +153,7 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
155
153
|
})
|
|
156
154
|
}
|
|
157
155
|
|
|
158
|
-
|
|
156
|
+
update() {
|
|
159
157
|
cancelAnimationFrame(this.af)
|
|
160
158
|
|
|
161
159
|
if (this.firstElementChild) {
|
|
@@ -168,8 +166,8 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
168
166
|
|
|
169
167
|
connectedCallback() {
|
|
170
168
|
this.templates()
|
|
171
|
-
this.cloning()
|
|
172
169
|
this.skewed()
|
|
170
|
+
this.cloning()
|
|
173
171
|
this.animation()
|
|
174
172
|
}
|
|
175
173
|
|