marquee-content 2.3.0 → 2.4.1
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 +0 -4
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +21 -8
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +29 -15
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
13
13
|
super();
|
|
14
14
|
this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
15
15
|
this.MM = this.gsap.matchMedia();
|
|
16
|
+
this.timeline = null;
|
|
16
17
|
this.update = this.update.bind(this);
|
|
17
18
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
18
19
|
this.resizeObserver.observe(this);
|
|
@@ -20,11 +21,6 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
20
21
|
static registerGSAP(gsap) {
|
|
21
22
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
22
23
|
}
|
|
23
|
-
breakpoints() {
|
|
24
|
-
this.breakpoint = "";
|
|
25
|
-
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
26
|
-
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
27
|
-
}
|
|
28
24
|
debounce(fn, delay) {
|
|
29
25
|
this.timer = null;
|
|
30
26
|
return (...args)=>{
|
|
@@ -32,6 +28,11 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
32
28
|
this.timer = setTimeout(()=>fn(...args), delay);
|
|
33
29
|
};
|
|
34
30
|
}
|
|
31
|
+
breakpoints() {
|
|
32
|
+
this.breakpoint = "";
|
|
33
|
+
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
34
|
+
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
35
|
+
}
|
|
35
36
|
templates() {
|
|
36
37
|
const wrapper = document.createElement("div");
|
|
37
38
|
wrapper.classList.add("marquee-wrapper");
|
|
@@ -74,11 +75,15 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
animation() {
|
|
78
|
+
if (this.timeline) {
|
|
79
|
+
this.timeline.kill();
|
|
80
|
+
this.timeline = null;
|
|
81
|
+
}
|
|
77
82
|
this.gsap.set(this.children, {
|
|
78
83
|
clearProps: true
|
|
79
84
|
});
|
|
80
85
|
this.MM.add(this.breakpoint, ()=>{
|
|
81
|
-
|
|
86
|
+
this.timeline = this.gsap.to(this.children, {
|
|
82
87
|
duration: this.dataset.mcDuration || 20,
|
|
83
88
|
x: "-100%",
|
|
84
89
|
ease: "none",
|
|
@@ -91,7 +96,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
91
96
|
}
|
|
92
97
|
}).totalProgress(0.5);
|
|
93
98
|
const ltrDirection = ()=>{
|
|
94
|
-
this.gsap.to(
|
|
99
|
+
this.gsap.to(this.timeline, {
|
|
95
100
|
timeScale: -1,
|
|
96
101
|
overwrite: true
|
|
97
102
|
});
|
|
@@ -102,7 +107,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
102
107
|
const handleScroll = ()=>{
|
|
103
108
|
const orientation = window.scrollY > currentScroll ? 1 : -1;
|
|
104
109
|
if (orientation !== scrollDirection) {
|
|
105
|
-
this.gsap.to(
|
|
110
|
+
this.gsap.to(this.timeline, {
|
|
106
111
|
timeScale: orientation,
|
|
107
112
|
overwrite: true
|
|
108
113
|
});
|
|
@@ -118,6 +123,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
118
123
|
if (this.dataset.mcDirection === "ltr") ltrDirection();
|
|
119
124
|
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
120
125
|
return ()=>{
|
|
126
|
+
if (this.timeline) {
|
|
127
|
+
this.timeline.kill();
|
|
128
|
+
this.timeline = null;
|
|
129
|
+
}
|
|
121
130
|
this.gsap.set(this.children, {
|
|
122
131
|
clearProps: true
|
|
123
132
|
});
|
|
@@ -143,6 +152,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
143
152
|
}
|
|
144
153
|
disconnectedCallback() {
|
|
145
154
|
cancelAnimationFrame(this.af);
|
|
155
|
+
if (this.timeline) {
|
|
156
|
+
this.timeline.kill();
|
|
157
|
+
this.timeline = null;
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
160
|
}
|
|
148
161
|
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,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M,gBAAgB;gBAClB,IAAI,gBAAgB;gBACpB,IAAI,kBAAkB;gBAEtB,MAAM,eAAe;oBACjB,MAAM,cAAc,AAAC,OAAO,UAAU,gBAAiB,IAAI;oBAE3D,IAAI,gBAAgB,iBAAiB;wBACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU;4BACxB,WAAW;4BACX,WAAW;wBACf;wBAEA,kBAAkB;oBACtB;oBAEA,gBAAgB,OAAO;gBAC3B;gBAEA,OAAO,iBAAiB,UAAU,cAAc;oBAAE,SAAS;oBAAM,SAAS;gBAAK;YACnF;YAEA,IAAI,IAAI,CAAC,QAAQ,gBAAgB,OAC7B;iBACG,IAAI,IAAI,CAAC,QAAQ,gBAAgB,QACpC;YAGJ,OAAO;gBACH,IAAI,IAAI,CAAC,UAAU;oBACf,IAAI,CAAC,SAAS;oBACd,IAAI,CAAC,WAAW;gBACpB;gBAEA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBAAE,YAAY;gBAAK;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,WAAW;QACpB;IACJ;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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.timeline = null;\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 this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\n };\n }\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\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 const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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, 10));\n const { style } = this;\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 if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = 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(this.timeline, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(this.timeline, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\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 init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -3,6 +3,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
3
3
|
super();
|
|
4
4
|
this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
5
5
|
this.MM = this.gsap.matchMedia();
|
|
6
|
+
this.timeline = null;
|
|
6
7
|
this.update = this.update.bind(this);
|
|
7
8
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
8
9
|
this.resizeObserver.observe(this);
|
|
@@ -10,11 +11,6 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
10
11
|
static registerGSAP(gsap) {
|
|
11
12
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
12
13
|
}
|
|
13
|
-
breakpoints() {
|
|
14
|
-
this.breakpoint = "";
|
|
15
|
-
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
16
|
-
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
17
|
-
}
|
|
18
14
|
debounce(fn, delay) {
|
|
19
15
|
this.timer = null;
|
|
20
16
|
return (...args)=>{
|
|
@@ -22,6 +18,11 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
22
18
|
this.timer = setTimeout(()=>fn(...args), delay);
|
|
23
19
|
};
|
|
24
20
|
}
|
|
21
|
+
breakpoints() {
|
|
22
|
+
this.breakpoint = "";
|
|
23
|
+
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
24
|
+
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
25
|
+
}
|
|
25
26
|
templates() {
|
|
26
27
|
const wrapper = document.createElement("div");
|
|
27
28
|
wrapper.classList.add("marquee-wrapper");
|
|
@@ -64,11 +65,15 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
animation() {
|
|
68
|
+
if (this.timeline) {
|
|
69
|
+
this.timeline.kill();
|
|
70
|
+
this.timeline = null;
|
|
71
|
+
}
|
|
67
72
|
this.gsap.set(this.children, {
|
|
68
73
|
clearProps: true
|
|
69
74
|
});
|
|
70
75
|
this.MM.add(this.breakpoint, ()=>{
|
|
71
|
-
|
|
76
|
+
this.timeline = this.gsap.to(this.children, {
|
|
72
77
|
duration: this.dataset.mcDuration || 20,
|
|
73
78
|
x: "-100%",
|
|
74
79
|
ease: "none",
|
|
@@ -81,7 +86,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
81
86
|
}
|
|
82
87
|
}).totalProgress(0.5);
|
|
83
88
|
const ltrDirection = ()=>{
|
|
84
|
-
this.gsap.to(
|
|
89
|
+
this.gsap.to(this.timeline, {
|
|
85
90
|
timeScale: -1,
|
|
86
91
|
overwrite: true
|
|
87
92
|
});
|
|
@@ -92,7 +97,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
92
97
|
const handleScroll = ()=>{
|
|
93
98
|
const orientation = window.scrollY > currentScroll ? 1 : -1;
|
|
94
99
|
if (orientation !== scrollDirection) {
|
|
95
|
-
this.gsap.to(
|
|
100
|
+
this.gsap.to(this.timeline, {
|
|
96
101
|
timeScale: orientation,
|
|
97
102
|
overwrite: true
|
|
98
103
|
});
|
|
@@ -108,6 +113,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
108
113
|
if (this.dataset.mcDirection === "ltr") ltrDirection();
|
|
109
114
|
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
110
115
|
return ()=>{
|
|
116
|
+
if (this.timeline) {
|
|
117
|
+
this.timeline.kill();
|
|
118
|
+
this.timeline = null;
|
|
119
|
+
}
|
|
111
120
|
this.gsap.set(this.children, {
|
|
112
121
|
clearProps: true
|
|
113
122
|
});
|
|
@@ -133,6 +142,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
133
142
|
}
|
|
134
143
|
disconnectedCallback() {
|
|
135
144
|
cancelAnimationFrame(this.af);
|
|
145
|
+
if (this.timeline) {
|
|
146
|
+
this.timeline.kill();
|
|
147
|
+
this.timeline = null;
|
|
148
|
+
}
|
|
136
149
|
}
|
|
137
150
|
}
|
|
138
151
|
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,
|
|
1
|
+
{"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI,CAAC,QAAQ;QA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;oBAAE,SAAS;oBAAM,SAAS;gBAAK;YACnF;YAEA,IAAI,IAAI,CAAC,QAAQ,gBAAgB,OAC7B;iBACG,IAAI,IAAI,CAAC,QAAQ,gBAAgB,QACpC;YAGJ,OAAO;gBACH,IAAI,IAAI,CAAC,UAAU;oBACf,IAAI,CAAC,SAAS;oBACd,IAAI,CAAC,WAAW;gBACpB;gBAEA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBAAE,YAAY;gBAAK;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,WAAW;QACpB;IACJ;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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.timeline = null;\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 this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\n };\n }\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\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 const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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, 10));\n const { style } = this;\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 if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = 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(this.timeline, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(this.timeline, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\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 init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
4
4
|
|
|
5
5
|
this.gsap = MarqueeContent.gsap || window.gsap;
|
|
6
6
|
this.MM = this.gsap.matchMedia();
|
|
7
|
+
this.timeline = null;
|
|
7
8
|
this.update = this.update.bind(this);
|
|
8
9
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
9
10
|
this.resizeObserver.observe(this);
|
|
@@ -13,6 +14,15 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
13
14
|
MarqueeContent.gsap = gsap;
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
debounce(fn, delay) {
|
|
18
|
+
this.timer = null;
|
|
19
|
+
|
|
20
|
+
return (...args) => {
|
|
21
|
+
if (this.timer) clearTimeout(this.timer);
|
|
22
|
+
this.timer = setTimeout(() => fn(...args), delay);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
breakpoints() {
|
|
17
27
|
this.breakpoint = '';
|
|
18
28
|
|
|
@@ -23,15 +33,6 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
debounce(fn, delay) {
|
|
27
|
-
this.timer = null;
|
|
28
|
-
|
|
29
|
-
return (...args) => {
|
|
30
|
-
if (this.timer) clearTimeout(this.timer);
|
|
31
|
-
this.timer = setTimeout(() => fn(...args), delay);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
36
|
templates() {
|
|
36
37
|
const wrapper = document.createElement('div');
|
|
37
38
|
wrapper.classList.add('marquee-wrapper');
|
|
@@ -93,10 +94,15 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
animation() {
|
|
97
|
+
if (this.timeline) {
|
|
98
|
+
this.timeline.kill();
|
|
99
|
+
this.timeline = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
this.gsap.set(this.children, { clearProps: true });
|
|
97
103
|
|
|
98
104
|
this.MM.add(this.breakpoint, () => {
|
|
99
|
-
|
|
105
|
+
this.timeline = this.gsap.to(this.children, {
|
|
100
106
|
duration: this.dataset.mcDuration || 20,
|
|
101
107
|
x: '-100%',
|
|
102
108
|
ease: 'none',
|
|
@@ -110,7 +116,7 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
110
116
|
}).totalProgress(0.5);
|
|
111
117
|
|
|
112
118
|
const ltrDirection = () => {
|
|
113
|
-
this.gsap.to(
|
|
119
|
+
this.gsap.to(this.timeline, {
|
|
114
120
|
timeScale: -1,
|
|
115
121
|
overwrite: true,
|
|
116
122
|
});
|
|
@@ -124,7 +130,7 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
124
130
|
const orientation = (window.scrollY > currentScroll) ? 1 : -1;
|
|
125
131
|
|
|
126
132
|
if (orientation !== scrollDirection) {
|
|
127
|
-
this.gsap.to(
|
|
133
|
+
this.gsap.to(this.timeline, {
|
|
128
134
|
timeScale: orientation,
|
|
129
135
|
overwrite: true,
|
|
130
136
|
});
|
|
@@ -145,9 +151,12 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
145
151
|
}
|
|
146
152
|
|
|
147
153
|
return () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
if (this.timeline) {
|
|
155
|
+
this.timeline.kill();
|
|
156
|
+
this.timeline = null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.gsap.set(this.children, { clearProps: true });
|
|
151
160
|
};
|
|
152
161
|
});
|
|
153
162
|
}
|
|
@@ -177,6 +186,11 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
177
186
|
|
|
178
187
|
disconnectedCallback() {
|
|
179
188
|
cancelAnimationFrame(this.af);
|
|
189
|
+
|
|
190
|
+
if (this.timeline) {
|
|
191
|
+
this.timeline.kill();
|
|
192
|
+
this.timeline = null;
|
|
193
|
+
}
|
|
180
194
|
}
|
|
181
195
|
}
|
|
182
196
|
|