marquee-content 2.4.0 → 3.0.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 +2 -6
- package/dist/index.js +30 -56
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +28 -56
- package/dist/index.module.js.map +1 -1
- package/package.json +20 -6
- package/src/demo.js +4 -0
- package/src/index.html +146 -0
- package/src/index.js +132 -159
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
<p align="center">A class for creating the running content effect, also known as a marquee or ticker.<br>Uses GSAP and Resize Observer for best performance.</p>
|
|
13
|
-
<p align="center"><sup>
|
|
13
|
+
<p align="center"><sup>1kB gzipped</sup></p>
|
|
14
14
|
<p align="center"><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></p>
|
|
15
15
|
<br>
|
|
16
16
|
|
|
@@ -32,10 +32,6 @@ import MarqueeContent from 'marquee-content';
|
|
|
32
32
|
|
|
33
33
|
gsap.registerPlugin(ScrollTrigger);
|
|
34
34
|
MarqueeContent.registerGSAP(gsap);
|
|
35
|
-
|
|
36
|
-
const marqueeContent = new MarqueeContent();
|
|
37
|
-
|
|
38
|
-
marqueeContent.init();
|
|
39
35
|
```
|
|
40
36
|
<br>
|
|
41
37
|
|
|
@@ -62,4 +58,4 @@ marqueeContent.init();
|
|
|
62
58
|
|
|
63
59
|
➤ **License**
|
|
64
60
|
|
|
65
|
-
marquee-content is released under MIT license.
|
|
61
|
+
marquee-content is released under MIT license.
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
|
|
1
2
|
function $parcel$defineInteropFlag(a) {
|
|
2
3
|
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
3
4
|
}
|
|
5
|
+
|
|
4
6
|
function $parcel$export(e, n, v, s) {
|
|
5
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
8
|
}
|
|
@@ -15,24 +17,24 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
15
17
|
this.MM = this.gsap.matchMedia();
|
|
16
18
|
this.timeline = null;
|
|
17
19
|
this.update = this.update.bind(this);
|
|
18
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)
|
|
20
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
19
21
|
this.resizeObserver.observe(this);
|
|
20
22
|
}
|
|
21
23
|
static registerGSAP(gsap) {
|
|
22
24
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
23
25
|
}
|
|
26
|
+
debounce = ()=>{
|
|
27
|
+
let timer;
|
|
28
|
+
return ()=>{
|
|
29
|
+
cancelAnimationFrame(timer);
|
|
30
|
+
timer = requestAnimationFrame(this.update);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
24
33
|
breakpoints() {
|
|
25
34
|
this.breakpoint = "";
|
|
26
35
|
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
27
36
|
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
28
37
|
}
|
|
29
|
-
debounce(fn, delay) {
|
|
30
|
-
this.timer = null;
|
|
31
|
-
return (...args)=>{
|
|
32
|
-
if (this.timer) clearTimeout(this.timer);
|
|
33
|
-
this.timer = setTimeout(()=>fn(...args), delay);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
38
|
templates() {
|
|
37
39
|
const wrapper = document.createElement("div");
|
|
38
40
|
wrapper.classList.add("marquee-wrapper");
|
|
@@ -51,14 +53,13 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
51
53
|
removingClones();
|
|
52
54
|
this.MM.add(this.breakpoint, ()=>{
|
|
53
55
|
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
54
|
-
if (this.childElementCount < requiredQuantity)
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (this.childElementCount < requiredQuantity) {
|
|
57
|
+
const clones = Array.from({
|
|
58
|
+
length: requiredQuantity - 1
|
|
59
|
+
}, ()=>this.firstElementChild.cloneNode(true));
|
|
60
|
+
this.append(...clones);
|
|
58
61
|
}
|
|
59
|
-
return
|
|
60
|
-
removingClones();
|
|
61
|
-
};
|
|
62
|
+
return removingClones;
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
skewed() {
|
|
@@ -74,7 +75,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
74
75
|
};
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
clearTimeline() {
|
|
78
79
|
if (this.timeline) {
|
|
79
80
|
this.timeline.kill();
|
|
80
81
|
this.timeline = null;
|
|
@@ -82,6 +83,9 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
82
83
|
this.gsap.set(this.children, {
|
|
83
84
|
clearProps: true
|
|
84
85
|
});
|
|
86
|
+
}
|
|
87
|
+
animation() {
|
|
88
|
+
if (this.timeline) this.clearTimeline.call(this);
|
|
85
89
|
this.MM.add(this.breakpoint, ()=>{
|
|
86
90
|
this.timeline = this.gsap.to(this.children, {
|
|
87
91
|
duration: this.dataset.mcDuration || 20,
|
|
@@ -92,44 +96,16 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
92
96
|
trigger: this,
|
|
93
97
|
start: "-=50% bottom",
|
|
94
98
|
end: "bottom top",
|
|
95
|
-
toggleActions: "resume pause resume pause"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.gsap.to(this.timeline, {
|
|
100
|
-
timeScale: -1,
|
|
101
|
-
overwrite: true
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const autoDirection = ()=>{
|
|
105
|
-
let currentScroll = 0;
|
|
106
|
-
let scrollDirection = 1;
|
|
107
|
-
const handleScroll = ()=>{
|
|
108
|
-
const orientation = window.scrollY > currentScroll ? 1 : -1;
|
|
109
|
-
if (orientation !== scrollDirection) {
|
|
110
|
-
this.gsap.to(this.timeline, {
|
|
111
|
-
timeScale: orientation,
|
|
112
|
-
overwrite: true
|
|
113
|
-
});
|
|
114
|
-
scrollDirection = orientation;
|
|
99
|
+
toggleActions: "resume pause resume pause",
|
|
100
|
+
onUpdate: (self)=>{
|
|
101
|
+
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
102
|
+
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
115
103
|
}
|
|
116
|
-
currentScroll = window.scrollY;
|
|
117
|
-
};
|
|
118
|
-
window.addEventListener("scroll", handleScroll, {
|
|
119
|
-
capture: true,
|
|
120
|
-
passive: true
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
if (this.dataset.mcDirection === "ltr") ltrDirection();
|
|
124
|
-
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
125
|
-
return ()=>{
|
|
126
|
-
if (this.timeline) {
|
|
127
|
-
this.timeline.kill();
|
|
128
|
-
this.timeline = null;
|
|
129
104
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
105
|
+
});
|
|
106
|
+
this.timeline.totalProgress(0.5);
|
|
107
|
+
return ()=>{
|
|
108
|
+
if (this.timeline) this.clearTimeline.call(this);
|
|
133
109
|
};
|
|
134
110
|
});
|
|
135
111
|
}
|
|
@@ -152,10 +128,8 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
152
128
|
}
|
|
153
129
|
disconnectedCallback() {
|
|
154
130
|
cancelAnimationFrame(this.af);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.timeline = null;
|
|
158
|
-
}
|
|
131
|
+
this.clearTimeline();
|
|
132
|
+
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
159
133
|
}
|
|
160
134
|
}
|
|
161
135
|
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAe,uDAA6B;IAC1C,aAAc;QACZ,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QACnC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IAClC;IAEA,OAAO,aAAa,IAAI,EAAE;QACxB,yCAAe,IAAI,GAAG;IACxB;IAEA,WAAW;QACT,IAAI;QAEJ,OAAO;YACL,qBAAqB;YACrB,QAAQ,sBAAsB,IAAI,CAAC,MAAM;QAC3C;IACF,EAAE;IAEF,cAAc;QACZ,IAAI,CAAC,UAAU,GAAG;QAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;aAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;IAE5D;IAEA,YAAY;QACV,MAAM,UAAU,SAAS,aAAa,CAAC;QACvC,QAAQ,SAAS,CAAC,GAAG,CAAC;QAEtB,MA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Z,IAAI,CAAC,SAAS;QAChB;IAEJ;IAEA,OAAO;QACL,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,SAAS;IAChB;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,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.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\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 const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\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 clearTimeline() {\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 animation() {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\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 onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\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 this.clearTimeline();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\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
|
@@ -5,24 +5,24 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
5
5
|
this.MM = this.gsap.matchMedia();
|
|
6
6
|
this.timeline = null;
|
|
7
7
|
this.update = this.update.bind(this);
|
|
8
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)
|
|
8
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
9
9
|
this.resizeObserver.observe(this);
|
|
10
10
|
}
|
|
11
11
|
static registerGSAP(gsap) {
|
|
12
12
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
13
13
|
}
|
|
14
|
+
debounce = ()=>{
|
|
15
|
+
let timer;
|
|
16
|
+
return ()=>{
|
|
17
|
+
cancelAnimationFrame(timer);
|
|
18
|
+
timer = requestAnimationFrame(this.update);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
14
21
|
breakpoints() {
|
|
15
22
|
this.breakpoint = "";
|
|
16
23
|
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
17
24
|
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
18
25
|
}
|
|
19
|
-
debounce(fn, delay) {
|
|
20
|
-
this.timer = null;
|
|
21
|
-
return (...args)=>{
|
|
22
|
-
if (this.timer) clearTimeout(this.timer);
|
|
23
|
-
this.timer = setTimeout(()=>fn(...args), delay);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
26
|
templates() {
|
|
27
27
|
const wrapper = document.createElement("div");
|
|
28
28
|
wrapper.classList.add("marquee-wrapper");
|
|
@@ -41,14 +41,13 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
41
41
|
removingClones();
|
|
42
42
|
this.MM.add(this.breakpoint, ()=>{
|
|
43
43
|
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
44
|
-
if (this.childElementCount < requiredQuantity)
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
if (this.childElementCount < requiredQuantity) {
|
|
45
|
+
const clones = Array.from({
|
|
46
|
+
length: requiredQuantity - 1
|
|
47
|
+
}, ()=>this.firstElementChild.cloneNode(true));
|
|
48
|
+
this.append(...clones);
|
|
48
49
|
}
|
|
49
|
-
return
|
|
50
|
-
removingClones();
|
|
51
|
-
};
|
|
50
|
+
return removingClones;
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
skewed() {
|
|
@@ -64,7 +63,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
64
63
|
};
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
|
-
|
|
66
|
+
clearTimeline() {
|
|
68
67
|
if (this.timeline) {
|
|
69
68
|
this.timeline.kill();
|
|
70
69
|
this.timeline = null;
|
|
@@ -72,6 +71,9 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
72
71
|
this.gsap.set(this.children, {
|
|
73
72
|
clearProps: true
|
|
74
73
|
});
|
|
74
|
+
}
|
|
75
|
+
animation() {
|
|
76
|
+
if (this.timeline) this.clearTimeline.call(this);
|
|
75
77
|
this.MM.add(this.breakpoint, ()=>{
|
|
76
78
|
this.timeline = this.gsap.to(this.children, {
|
|
77
79
|
duration: this.dataset.mcDuration || 20,
|
|
@@ -82,44 +84,16 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
82
84
|
trigger: this,
|
|
83
85
|
start: "-=50% bottom",
|
|
84
86
|
end: "bottom top",
|
|
85
|
-
toggleActions: "resume pause resume pause"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.gsap.to(this.timeline, {
|
|
90
|
-
timeScale: -1,
|
|
91
|
-
overwrite: true
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
const autoDirection = ()=>{
|
|
95
|
-
let currentScroll = 0;
|
|
96
|
-
let scrollDirection = 1;
|
|
97
|
-
const handleScroll = ()=>{
|
|
98
|
-
const orientation = window.scrollY > currentScroll ? 1 : -1;
|
|
99
|
-
if (orientation !== scrollDirection) {
|
|
100
|
-
this.gsap.to(this.timeline, {
|
|
101
|
-
timeScale: orientation,
|
|
102
|
-
overwrite: true
|
|
103
|
-
});
|
|
104
|
-
scrollDirection = orientation;
|
|
87
|
+
toggleActions: "resume pause resume pause",
|
|
88
|
+
onUpdate: (self)=>{
|
|
89
|
+
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
90
|
+
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
105
91
|
}
|
|
106
|
-
currentScroll = window.scrollY;
|
|
107
|
-
};
|
|
108
|
-
window.addEventListener("scroll", handleScroll, {
|
|
109
|
-
capture: true,
|
|
110
|
-
passive: true
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
if (this.dataset.mcDirection === "ltr") ltrDirection();
|
|
114
|
-
else if (this.dataset.mcDirection === "auto") autoDirection();
|
|
115
|
-
return ()=>{
|
|
116
|
-
if (this.timeline) {
|
|
117
|
-
this.timeline.kill();
|
|
118
|
-
this.timeline = null;
|
|
119
92
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
93
|
+
});
|
|
94
|
+
this.timeline.totalProgress(0.5);
|
|
95
|
+
return ()=>{
|
|
96
|
+
if (this.timeline) this.clearTimeline.call(this);
|
|
123
97
|
};
|
|
124
98
|
});
|
|
125
99
|
}
|
|
@@ -142,10 +116,8 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
142
116
|
}
|
|
143
117
|
disconnectedCallback() {
|
|
144
118
|
cancelAnimationFrame(this.af);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.timeline = null;
|
|
148
|
-
}
|
|
119
|
+
this.clearTimeline();
|
|
120
|
+
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
149
121
|
}
|
|
150
122
|
}
|
|
151
123
|
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;
|
|
1
|
+
{"mappings":"AAAe,uDAA6B;IAC1C,aAAc;QACZ,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QACnC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IAClC;IAEA,OAAO,aAAa,IAAI,EAAE;QACxB,yCAAe,IAAI,GAAG;IACxB;IAEA,WAAW;QACT,IAAI;QAEJ,OAAO;YACL,qBAAqB;YACrB,QAAQ,sBAAsB,IAAI,CAAC,MAAM;QAC3C;IACF,EAAE;IAEF,cAAc;QACZ,IAAI,CAAC,UAAU,GAAG;QAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;aAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAA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AC,IAAI,CAAC,IAAI;YAEhC;QACF;IACF;IAEA,SAAS;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACxB,IAAI,CAAC,EAAE,GAAG,sBAAsB;YAC9B,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAChB;IAEJ;IAEA,OAAO;QACL,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,SAAS;IAChB;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,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.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\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 const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\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 clearTimeline() {\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 animation() {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\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 onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\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 this.clearTimeline();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marquee-content",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Class for creating the running content effect, also known as a marquee or ticker.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,16 +11,30 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ux-ui-pro/marquee-content/issues"
|
|
13
13
|
},
|
|
14
|
-
"source": "src/index.js",
|
|
15
14
|
"main": "dist/index.js",
|
|
15
|
+
"source": "dist/index.html",
|
|
16
16
|
"module": "dist/index.module.js",
|
|
17
|
+
"targets": {
|
|
18
|
+
"main": {
|
|
19
|
+
"source": "src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"module": {
|
|
22
|
+
"source": "src/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"scripts": {
|
|
18
|
-
"serve": "parcel
|
|
26
|
+
"serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
|
|
19
27
|
"build": "parcel build",
|
|
20
|
-
"clean": "rm -rf dist .parcel-cache"
|
|
28
|
+
"clean": "rm -rf dist .parcel-cache",
|
|
29
|
+
"lint:js": "eslint --ext .js,.vue .",
|
|
30
|
+
"lintfix": "yarn lint:js --fix"
|
|
21
31
|
},
|
|
22
32
|
"devDependencies": {
|
|
23
|
-
"
|
|
33
|
+
"eslint": "^7.32.0 || ^8.52.0",
|
|
34
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
35
|
+
"eslint-plugin-import": "^2.29.0",
|
|
36
|
+
"parcel": "^2.10.1",
|
|
37
|
+
"postcss-html": "^1.5.0"
|
|
24
38
|
},
|
|
25
39
|
"keywords": [
|
|
26
40
|
"marquee",
|
|
@@ -38,4 +52,4 @@
|
|
|
38
52
|
"effects",
|
|
39
53
|
"gsap"
|
|
40
54
|
]
|
|
41
|
-
}
|
|
55
|
+
}
|
package/src/demo.js
ADDED
package/src/index.html
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="ru">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="robots" content="index, follow" />
|
|
6
|
+
<meta
|
|
7
|
+
name="viewport"
|
|
8
|
+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0"
|
|
9
|
+
/>
|
|
10
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
11
|
+
<title></title>
|
|
12
|
+
<style>
|
|
13
|
+
html {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
font-family: system-ui, -apple-system, "Open Sans", "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
16
|
+
font-size: 10px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
body {
|
|
20
|
+
--c-cells: hsl(0 0% 95%);
|
|
21
|
+
font-feature-settings: "kern" 1,"liga" 0;
|
|
22
|
+
font-size: 1.6rem;
|
|
23
|
+
font-weight: 400;
|
|
24
|
+
line-height: 1.5;
|
|
25
|
+
background-image: -o-linear-gradient(45deg,var(--c-cells) 25%,transparent 25%),-o-linear-gradient(135deg,var(--c-cells) 25%,transparent 25%),-o-linear-gradient(45deg,transparent 75%,var(--c-cells) 75%),-o-linear-gradient(135deg,transparent 75%,var(--c-cells) 75%);
|
|
26
|
+
background-image: linear-gradient(45deg,var(--c-cells) 25%,transparent 25%),linear-gradient(-45deg,var(--c-cells) 25%,transparent 25%),linear-gradient(45deg,transparent 75%,var(--c-cells) 75%),linear-gradient(-45deg,transparent 75%,var(--c-cells) 75%);
|
|
27
|
+
background-size: 2rem 2rem;
|
|
28
|
+
background-position: 0 0,0 1rem,1rem -1rem,-1rem 0;
|
|
29
|
+
margin: 40px;
|
|
30
|
+
width: 100vw;
|
|
31
|
+
overflow-x: clip;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
marquee-content {
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
position: relative;
|
|
37
|
+
width: 100vw;
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
align-items: center;
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.marquee-wrapper {
|
|
45
|
+
will-change: transform;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
html{font-family: system-ui, -apple-system, "Open Sans", "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";font-size: 10px}body{margin: 80px 0 400px;font-feature-settings: "kern" 1,"liga" 0;font-size: 1.6rem;font-weight: 400;line-height: 1.5;color: #444}html,body,input,textarea,button{-webkit-font-smoothing: subpixel-antialiased}.marquee-content{pointer-events: none;max-width: 100vw;justify-content: center;align-items: center;display: flex;position: relative;overflow: hidden}.font{white-space: nowrap}.alkatra{font-family: 'Alkatra', cursive;font-weight: 700;font-size: 48px}.anton{font-family: 'Anton', sans-serif;font-weight: 700;font-size: 40px}.pt{font-family: 'PT Sans Narrow', sans-serif;font-weight: 400;font-size: 52px}.lobster{font-family: 'Lobster', cursive;font-weight: 400;font-size: 50px}.prompt{font-family: 'Prompt', sans-serif;font-weight: 500;font-size: 48px}ul{list-style: none;margin: 0;padding: 0;display: flex;align-items: center}li{padding: 0 10px;text-align: center}.example-1 li{padding: 0 0 0 66px;background:url("data:image/svg xml,<svg width='26' height='26' viewBox='0 0 26 26' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M15.0527 10.9474L13 0L10.9473 10.9474L0 13L10.9473 15.0526L13 26L15.0527 15.0526L26 13L15.0527 10.9474Z' fill='#444444'/></svg>")center left 20px / 26px 26pxno-repeat}.example-2 li{padding: 0 15px}.example-3 li{position: relative;padding: 0 0 0 56px}.example-3 li::before{content: '';position: absolute;top: 0;right: -33px;bottom: 0;left: auto;margin: auto;width: 7px;height: 7px;transform: translateY(5px);background: #444;border-radius: 100%}.example-4{text-transform: uppercase}.data-code{margin: 0 auto;padding: 120px 20px 30px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<section class="example-1">
|
|
53
|
+
<marquee-content data-mc-duration="60" role="marquee">
|
|
54
|
+
<ul class="font alkatra">
|
|
55
|
+
<li>Monarch</li>
|
|
56
|
+
<li>Benassi</li>
|
|
57
|
+
<li>Air Max</li>
|
|
58
|
+
<li>Cortez</li>
|
|
59
|
+
<li>Jordan</li>
|
|
60
|
+
<li>Presto</li>
|
|
61
|
+
<li>Vomero</li>
|
|
62
|
+
<li>Pegasus</li>
|
|
63
|
+
</ul>
|
|
64
|
+
</marquee-content>
|
|
65
|
+
</section>
|
|
66
|
+
|
|
67
|
+
<section class="example-7">
|
|
68
|
+
<marquee-content data-mc-duration="20" role="marquee">
|
|
69
|
+
<ul>
|
|
70
|
+
<li><img src="//fastly.picsum.photos/id/634/180/100.jpg?hmac=qB-PFAiiEVuXFwVxRbYUzImrQ4RZ2np6oWeK-XHPnXk" alt=""/></li>
|
|
71
|
+
<li><img src="//fastly.picsum.photos/id/719/180/100.jpg?hmac=_Toti9aQVjjnNHabofyq_la4a0kIFSDp3o65zxnvtRY" alt=""/></li>
|
|
72
|
+
<li><img src="//fastly.picsum.photos/id/235/180/100.jpg?hmac=5KlYbDb93R7me0GThn6FFoK_OZ8ziPn-fb98FHIMb5c" alt=""/></li>
|
|
73
|
+
<li><img src="//fastly.picsum.photos/id/1050/180/100.jpg?hmac=f9i0nGYKBetkohJors44GETXmUhSbLcXMUlSvMCluJY" alt=""/></li>
|
|
74
|
+
</ul>
|
|
75
|
+
</marquee-content>
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<section class="example-2">
|
|
79
|
+
<marquee-content data-mc-duration="60" data-mc-direction="ltr" role="marquee">
|
|
80
|
+
<ul>
|
|
81
|
+
<li><span class="font anton">Monarch</span></li>
|
|
82
|
+
<li><span class="font pt">Benassi</span></li>
|
|
83
|
+
<li><span class="font lobster">Air Max</span></li>
|
|
84
|
+
<li><span class="font prompt">Cortez</span></li>
|
|
85
|
+
<li><span class="font anton">Jordan</span></li>
|
|
86
|
+
<li><span class="font pt">Presto</span></li>
|
|
87
|
+
<li><span class="font prompt">Tempo</span></li>
|
|
88
|
+
<li><span class="font anton">Vomero</span></li>
|
|
89
|
+
<li><span class="font pt">Pegasus</span></li>
|
|
90
|
+
</ul>
|
|
91
|
+
</marquee-content>
|
|
92
|
+
</section>
|
|
93
|
+
|
|
94
|
+
<section class="example-3">
|
|
95
|
+
<marquee-content data-mc-duration="60" data-mc-direction="auto" role="marquee">
|
|
96
|
+
<ul class="font lobster">
|
|
97
|
+
<li>Monarch</li>
|
|
98
|
+
<li>Benassi</li>
|
|
99
|
+
<li>Air Max</li>
|
|
100
|
+
<li>Cortez</li>
|
|
101
|
+
<li>Jordan</li>
|
|
102
|
+
<li>Presto</li>
|
|
103
|
+
<li>Tempo</li>
|
|
104
|
+
<li>Vomero</li>
|
|
105
|
+
<li>Pegasus</li>
|
|
106
|
+
</ul>
|
|
107
|
+
</marquee-content>
|
|
108
|
+
</section>
|
|
109
|
+
|
|
110
|
+
<section class="example-4">
|
|
111
|
+
<marquee-content data-mc-duration="60" data-mc-skew="-3" role="marquee">
|
|
112
|
+
<ul class="font pt">
|
|
113
|
+
<li>Monarch</li>
|
|
114
|
+
<li>Benassi</li>
|
|
115
|
+
<li>Air Max</li>
|
|
116
|
+
<li>Cortez</li>
|
|
117
|
+
<li>Jordan</li>
|
|
118
|
+
<li>Presto</li>
|
|
119
|
+
<li>Tempo</li>
|
|
120
|
+
<li>Vomero</li>
|
|
121
|
+
<li>Pegasus</li>
|
|
122
|
+
</ul>
|
|
123
|
+
</marquee-content>
|
|
124
|
+
</section>
|
|
125
|
+
|
|
126
|
+
<section class="example-6">
|
|
127
|
+
<marquee-content data-mc-duration="5" data-mc-max="992" role="marquee">
|
|
128
|
+
<ul class="font pt">
|
|
129
|
+
<li>Jordan</li>
|
|
130
|
+
</ul>
|
|
131
|
+
</marquee-content>
|
|
132
|
+
</section>
|
|
133
|
+
|
|
134
|
+
<section class="example-5">
|
|
135
|
+
<marquee-content data-mc-duration="5" data-mc-min="992" role="marquee">
|
|
136
|
+
<ul class="font pt">
|
|
137
|
+
<li>Cortez</li>
|
|
138
|
+
</ul>
|
|
139
|
+
</marquee-content>
|
|
140
|
+
</section>
|
|
141
|
+
|
|
142
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
|
143
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
|
|
144
|
+
<script type="module" src="demo.js"></script>
|
|
145
|
+
</body>
|
|
146
|
+
</html>
|
package/src/index.js
CHANGED
|
@@ -1,199 +1,172 @@
|
|
|
1
1
|
export default class MarqueeContent extends HTMLElement {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
|
|
5
|
+
this.gsap = MarqueeContent.gsap || window.gsap;
|
|
6
|
+
this.MM = this.gsap.matchMedia();
|
|
7
|
+
this.timeline = null;
|
|
8
|
+
this.update = this.update.bind(this);
|
|
9
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
10
|
+
this.resizeObserver.observe(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static registerGSAP(gsap) {
|
|
14
|
+
MarqueeContent.gsap = gsap;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
debounce = () => {
|
|
18
|
+
let timer;
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
cancelAnimationFrame(timer);
|
|
22
|
+
timer = requestAnimationFrame(this.update);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
breakpoints() {
|
|
27
|
+
this.breakpoint = '';
|
|
28
|
+
|
|
29
|
+
if (this.dataset.mcMax) {
|
|
30
|
+
this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
31
|
+
} else if (this.dataset.mcMin) {
|
|
32
|
+
this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
11
33
|
}
|
|
34
|
+
}
|
|
12
35
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
36
|
+
templates() {
|
|
37
|
+
const wrapper = document.createElement('div');
|
|
38
|
+
wrapper.classList.add('marquee-wrapper');
|
|
16
39
|
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
const inner = document.createElement('div');
|
|
41
|
+
inner.classList.add('marquee-inner');
|
|
42
|
+
inner.style.display = 'inline-block';
|
|
43
|
+
inner.style.whiteSpace = 'nowrap';
|
|
19
44
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} else if (this.dataset.mcMin) {
|
|
23
|
-
this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
24
|
-
}
|
|
45
|
+
while (this.firstChild) {
|
|
46
|
+
inner.appendChild(this.firstChild);
|
|
25
47
|
}
|
|
26
48
|
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
wrapper.appendChild(inner);
|
|
50
|
+
this.appendChild(wrapper);
|
|
51
|
+
}
|
|
29
52
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
cloning() {
|
|
54
|
+
const removingClones = () => {
|
|
55
|
+
while (this.childElementCount > 1) {
|
|
56
|
+
this.removeChild(this.lastChild);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
35
59
|
|
|
36
|
-
|
|
37
|
-
const wrapper = document.createElement('div');
|
|
38
|
-
wrapper.classList.add('marquee-wrapper');
|
|
60
|
+
removingClones();
|
|
39
61
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
inner.style.display = 'inline-block';
|
|
43
|
-
inner.style.whiteSpace = 'nowrap';
|
|
62
|
+
this.MM.add(this.breakpoint, () => {
|
|
63
|
+
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
44
64
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
if (this.childElementCount < requiredQuantity) {
|
|
66
|
+
const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));
|
|
67
|
+
this.append(...clones);
|
|
68
|
+
}
|
|
48
69
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
return removingClones;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
52
73
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
while (this.childElementCount > 1) {
|
|
56
|
-
this.removeChild(this.lastChild);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
74
|
+
skewed() {
|
|
75
|
+
if (!this.dataset.mcSkew) return;
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
78
|
+
const { style } = this;
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
this.MM.add(this.breakpoint, () => {
|
|
81
|
+
style.transformOrigin = 'center center';
|
|
82
|
+
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
83
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
64
84
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
85
|
+
return () => {
|
|
86
|
+
style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
clearTimeline() {
|
|
92
|
+
if (this.timeline) {
|
|
93
|
+
this.timeline.kill();
|
|
94
|
+
this.timeline = null;
|
|
77
95
|
}
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
83
|
-
const { style } = this;
|
|
84
|
-
|
|
85
|
-
this.MM.add(this.breakpoint, () => {
|
|
86
|
-
style.transformOrigin = 'center center';
|
|
87
|
-
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
88
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
97
|
+
this.gsap.set(this.children, { clearProps: true });
|
|
98
|
+
}
|
|
89
99
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
100
|
+
animation() {
|
|
101
|
+
if (this.timeline) {
|
|
102
|
+
this.clearTimeline.call(this);
|
|
94
103
|
}
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
ease: 'none',
|
|
109
|
-
repeat: -1,
|
|
110
|
-
scrollTrigger: {
|
|
111
|
-
trigger: this,
|
|
112
|
-
start: '-=50% bottom',
|
|
113
|
-
end: 'bottom top',
|
|
114
|
-
toggleActions: 'resume pause resume pause',
|
|
115
|
-
},
|
|
116
|
-
}).totalProgress(0.5);
|
|
117
|
-
|
|
118
|
-
const ltrDirection = () => {
|
|
119
|
-
this.gsap.to(this.timeline, {
|
|
120
|
-
timeScale: -1,
|
|
121
|
-
overwrite: true,
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const autoDirection = () => {
|
|
126
|
-
let currentScroll = 0;
|
|
127
|
-
let scrollDirection = 1;
|
|
128
|
-
|
|
129
|
-
const handleScroll = () => {
|
|
130
|
-
const orientation = (window.scrollY > currentScroll) ? 1 : -1;
|
|
131
|
-
|
|
132
|
-
if (orientation !== scrollDirection) {
|
|
133
|
-
this.gsap.to(this.timeline, {
|
|
134
|
-
timeScale: orientation,
|
|
135
|
-
overwrite: true,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
scrollDirection = orientation;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
currentScroll = window.scrollY;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
window.addEventListener('scroll', handleScroll, { capture: true, passive: true });
|
|
145
|
-
};
|
|
146
|
-
|
|
105
|
+
this.MM.add(this.breakpoint, () => {
|
|
106
|
+
this.timeline = this.gsap.to(this.children, {
|
|
107
|
+
duration: this.dataset.mcDuration || 20,
|
|
108
|
+
x: '-100%',
|
|
109
|
+
ease: 'none',
|
|
110
|
+
repeat: -1,
|
|
111
|
+
scrollTrigger: {
|
|
112
|
+
trigger: this,
|
|
113
|
+
start: '-=50% bottom',
|
|
114
|
+
end: 'bottom top',
|
|
115
|
+
toggleActions: 'resume pause resume pause',
|
|
116
|
+
onUpdate: (self) => {
|
|
147
117
|
if (this.dataset.mcDirection === 'ltr') {
|
|
148
|
-
|
|
118
|
+
this.timeline.timeScale(-1);
|
|
149
119
|
} else if (this.dataset.mcDirection === 'auto') {
|
|
150
|
-
|
|
120
|
+
this.timeline.timeScale(self.direction);
|
|
151
121
|
}
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
152
125
|
|
|
153
|
-
|
|
154
|
-
if (this.timeline) {
|
|
155
|
-
this.timeline.kill();
|
|
156
|
-
this.timeline = null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
this.gsap.set(this.children, { clearProps: true });
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
update() {
|
|
165
|
-
cancelAnimationFrame(this.af);
|
|
126
|
+
this.timeline.totalProgress(0.5);
|
|
166
127
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.animation();
|
|
171
|
-
});
|
|
128
|
+
return () => {
|
|
129
|
+
if (this.timeline) {
|
|
130
|
+
this.clearTimeline.call(this);
|
|
172
131
|
}
|
|
173
|
-
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
174
135
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
136
|
+
update() {
|
|
137
|
+
cancelAnimationFrame(this.af);
|
|
138
|
+
|
|
139
|
+
if (this.firstElementChild) {
|
|
140
|
+
this.af = requestAnimationFrame(() => {
|
|
179
141
|
this.cloning();
|
|
180
142
|
this.animation();
|
|
143
|
+
});
|
|
181
144
|
}
|
|
145
|
+
}
|
|
182
146
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
147
|
+
init() {
|
|
148
|
+
this.breakpoints();
|
|
149
|
+
this.templates();
|
|
150
|
+
this.skewed();
|
|
151
|
+
this.cloning();
|
|
152
|
+
this.animation();
|
|
153
|
+
}
|
|
186
154
|
|
|
187
|
-
|
|
188
|
-
|
|
155
|
+
connectedCallback() {
|
|
156
|
+
this.init();
|
|
157
|
+
}
|
|
189
158
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
159
|
+
disconnectedCallback() {
|
|
160
|
+
cancelAnimationFrame(this.af);
|
|
161
|
+
|
|
162
|
+
this.clearTimeline();
|
|
163
|
+
|
|
164
|
+
if (this.resizeObserver) {
|
|
165
|
+
this.resizeObserver.disconnect();
|
|
194
166
|
}
|
|
167
|
+
}
|
|
195
168
|
}
|
|
196
169
|
|
|
197
170
|
if (!customElements.get('marquee-content')) {
|
|
198
|
-
|
|
171
|
+
customElements.define('marquee-content', MarqueeContent);
|
|
199
172
|
}
|