marquee-content 3.0.0 → 3.1.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 +8 -8
- package/dist/index.468c551c.js +764 -0
- package/dist/index.html +262 -0
- package/dist/index.js +96 -89
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +96 -89
- package/dist/index.module.js.map +1 -1
- package/package.json +5 -5
- package/src/index.html +6 -2
- package/src/index.js +22 -123
- package/src/utils/animation.js +39 -0
- package/src/utils/breakpoints.js +11 -0
- package/src/utils/clearTimeline.js +10 -0
- package/src/utils/cloning.js +22 -0
- package/src/utils/skewed.js +18 -0
- package/src/utils/update.js +15 -0
- package/src/demo.js +0 -4
package/dist/index.module.js
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
+
function $0247ba718e967cec$var$breakpoints() {
|
|
2
|
+
this.breakpoint = "";
|
|
3
|
+
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
4
|
+
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
5
|
+
}
|
|
6
|
+
var $0247ba718e967cec$export$2e2bcd8739ae039 = $0247ba718e967cec$var$breakpoints;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $2b68722c48061d80$var$cloning() {
|
|
10
|
+
const removingClones = ()=>{
|
|
11
|
+
while(this.childElementCount > 1)this.removeChild(this.lastChild);
|
|
12
|
+
};
|
|
13
|
+
removingClones();
|
|
14
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
15
|
+
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
16
|
+
if (this.childElementCount < requiredQuantity) {
|
|
17
|
+
const clones = Array.from({
|
|
18
|
+
length: requiredQuantity - 1
|
|
19
|
+
}, ()=>this.firstElementChild.cloneNode(true));
|
|
20
|
+
this.append(...clones);
|
|
21
|
+
}
|
|
22
|
+
return removingClones;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
var $2b68722c48061d80$export$2e2bcd8739ae039 = $2b68722c48061d80$var$cloning;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function $dfb0cb0db0a7e917$var$skewed() {
|
|
29
|
+
if (!this.dataset.mcSkew) return;
|
|
30
|
+
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
31
|
+
const { style: style } = this;
|
|
32
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
33
|
+
style.transformOrigin = "center center";
|
|
34
|
+
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
35
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
36
|
+
return ()=>{
|
|
37
|
+
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var $dfb0cb0db0a7e917$export$2e2bcd8739ae039 = $dfb0cb0db0a7e917$var$skewed;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function $44f92944fa78205a$var$clearTimeline() {
|
|
45
|
+
if (this.timeline) {
|
|
46
|
+
this.timeline.kill();
|
|
47
|
+
this.timeline = null;
|
|
48
|
+
}
|
|
49
|
+
this.gsap.set(this.children, {
|
|
50
|
+
clearProps: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var $44f92944fa78205a$export$2e2bcd8739ae039 = $44f92944fa78205a$var$clearTimeline;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function $5138c3f25fef74d5$var$animation() {
|
|
57
|
+
if (this.timeline) (0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
58
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
59
|
+
this.timeline = this.gsap.to(this.children, {
|
|
60
|
+
duration: this.dataset.mcDuration || 20,
|
|
61
|
+
x: "-100%",
|
|
62
|
+
repeat: -1,
|
|
63
|
+
ease: "none",
|
|
64
|
+
scrollTrigger: {
|
|
65
|
+
trigger: this,
|
|
66
|
+
start: "-=50% bottom",
|
|
67
|
+
end: "bottom top",
|
|
68
|
+
toggleActions: "resume pause resume pause",
|
|
69
|
+
onUpdate: (self)=>{
|
|
70
|
+
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
71
|
+
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this.timeline.totalProgress(0.5);
|
|
76
|
+
return ()=>{
|
|
77
|
+
if (this.timeline) (0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
var $5138c3f25fef74d5$export$2e2bcd8739ae039 = $5138c3f25fef74d5$var$animation;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
1
85
|
class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
2
86
|
constructor(){
|
|
3
87
|
super();
|
|
@@ -18,106 +102,29 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
18
102
|
timer = requestAnimationFrame(this.update);
|
|
19
103
|
};
|
|
20
104
|
};
|
|
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
|
-
}
|
|
26
|
-
templates() {
|
|
27
|
-
const wrapper = document.createElement("div");
|
|
28
|
-
wrapper.classList.add("marquee-wrapper");
|
|
29
|
-
const inner = document.createElement("div");
|
|
30
|
-
inner.classList.add("marquee-inner");
|
|
31
|
-
inner.style.display = "inline-block";
|
|
32
|
-
inner.style.whiteSpace = "nowrap";
|
|
33
|
-
while(this.firstChild)inner.appendChild(this.firstChild);
|
|
34
|
-
wrapper.appendChild(inner);
|
|
35
|
-
this.appendChild(wrapper);
|
|
36
|
-
}
|
|
37
|
-
cloning() {
|
|
38
|
-
const removingClones = ()=>{
|
|
39
|
-
while(this.childElementCount > 1)this.removeChild(this.lastChild);
|
|
40
|
-
};
|
|
41
|
-
removingClones();
|
|
42
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
43
|
-
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
44
|
-
if (this.childElementCount < requiredQuantity) {
|
|
45
|
-
const clones = Array.from({
|
|
46
|
-
length: requiredQuantity - 1
|
|
47
|
-
}, ()=>this.firstElementChild.cloneNode(true));
|
|
48
|
-
this.append(...clones);
|
|
49
|
-
}
|
|
50
|
-
return removingClones;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
skewed() {
|
|
54
|
-
if (!this.dataset.mcSkew) return;
|
|
55
|
-
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
56
|
-
const { style: style } = this;
|
|
57
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
58
|
-
style.transformOrigin = "center center";
|
|
59
|
-
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
60
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
61
|
-
return ()=>{
|
|
62
|
-
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
clearTimeline() {
|
|
67
|
-
if (this.timeline) {
|
|
68
|
-
this.timeline.kill();
|
|
69
|
-
this.timeline = null;
|
|
70
|
-
}
|
|
71
|
-
this.gsap.set(this.children, {
|
|
72
|
-
clearProps: true
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
animation() {
|
|
76
|
-
if (this.timeline) this.clearTimeline.call(this);
|
|
77
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
78
|
-
this.timeline = this.gsap.to(this.children, {
|
|
79
|
-
duration: this.dataset.mcDuration || 20,
|
|
80
|
-
x: "-100%",
|
|
81
|
-
ease: "none",
|
|
82
|
-
repeat: -1,
|
|
83
|
-
scrollTrigger: {
|
|
84
|
-
trigger: this,
|
|
85
|
-
start: "-=50% bottom",
|
|
86
|
-
end: "bottom top",
|
|
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);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
this.timeline.totalProgress(0.5);
|
|
95
|
-
return ()=>{
|
|
96
|
-
if (this.timeline) this.clearTimeline.call(this);
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
105
|
update() {
|
|
101
106
|
cancelAnimationFrame(this.af);
|
|
102
107
|
if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
(0, $2b68722c48061d80$export$2e2bcd8739ae039).call(this);
|
|
109
|
+
(0, $5138c3f25fef74d5$export$2e2bcd8739ae039).call(this);
|
|
105
110
|
});
|
|
106
111
|
}
|
|
107
112
|
init() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
(0, $0247ba718e967cec$export$2e2bcd8739ae039).call(this);
|
|
114
|
+
(0, $dfb0cb0db0a7e917$export$2e2bcd8739ae039).call(this);
|
|
115
|
+
(0, $2b68722c48061d80$export$2e2bcd8739ae039).call(this);
|
|
116
|
+
(0, $5138c3f25fef74d5$export$2e2bcd8739ae039).call(this);
|
|
117
|
+
}
|
|
118
|
+
destroy() {
|
|
119
|
+
cancelAnimationFrame(this.af);
|
|
120
|
+
(0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
121
|
+
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
113
122
|
}
|
|
114
123
|
connectedCallback() {
|
|
115
124
|
this.init();
|
|
116
125
|
}
|
|
117
126
|
disconnectedCallback() {
|
|
118
|
-
|
|
119
|
-
this.clearTimeline();
|
|
120
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
127
|
+
this.destroy();
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"ACAA,SAAS;IACP,IAAI,CAAC,UAAU,GAAG;IAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;SAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;AAE5D;IAEA,2CAAe;;;ACVf,SAAS;IACP,MAAM,iBAAiB;QACrB,MAAO,IAAI,CAAC,iBAAiB,GAAG,EAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;IAEnC;IAEA;IAEA,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE;QAC3B,MAAM,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,GAAG;QAE3F,IAAI,IAAI,CAAC,iBAAiB,GAAG,kBAAkB;YAC7C,MAAM,SAAS,MAAM,IAAI,CAAC;gBAAE,QAAQ,mBAAmB;YAAE,GAAG,IAAM,IAAI,CAAC,iBAAiB,CAAC,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;QACrB;IAEJ;IAEA,OAAO;QACL,CAAA,GAAA,wCAAU,EAAE,IAAI,CAAC,IAAI;QACrB,CAAA,GAAA,wCAAK,EAAE,IAAI,CAAC,IAAI;QAChB,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;QACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;IACrB;IAEA,UAAU;QACR,qBAAqB,IAAI,CAAC,EAAE;QAE5B,CAAA,GAAA,wCAAY,EAAE,IAAI,CAAC,IAAI;QAEvB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,IAAI,CAAC,OAAO;IACd;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js","src/utils/breakpoints.js","src/utils/cloning.js","src/utils/skewed.js","src/utils/animation.js","src/utils/clearTimeline.js"],"sourcesContent":["import breakpoints from './utils/breakpoints';\nimport cloning from './utils/cloning';\nimport skewed from './utils/skewed';\nimport animation from './utils/animation';\nimport clearTimeline from './utils/clearTimeline';\n\nexport 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 update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n cloning.call(this);\n animation.call(this);\n });\n }\n }\n\n init() {\n breakpoints.call(this);\n skewed.call(this);\n cloning.call(this);\n animation.call(this);\n }\n\n destroy() {\n cancelAnimationFrame(this.af);\n\n clearTimeline.call(this);\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n this.destroy();\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n","function 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\nexport default breakpoints;\n","function 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\nexport default cloning;\n","function 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\nexport default skewed;\n","import clearTimeline from './clearTimeline';\n\nfunction animation() {\n if (this.timeline) {\n 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 repeat: -1,\n ease: 'none',\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 clearTimeline.call(this);\n }\n };\n });\n}\n\nexport default animation;\n","function 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\nexport default clearTimeline;\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.
|
|
3
|
+
"version": "3.1.1",
|
|
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",
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
|
|
27
|
-
"build": "parcel build",
|
|
28
26
|
"clean": "rm -rf dist .parcel-cache",
|
|
29
|
-
"
|
|
27
|
+
"serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
|
|
28
|
+
"build": "yarn clean && parcel build",
|
|
29
|
+
"lint:js": "eslint --ext .js",
|
|
30
30
|
"lintfix": "yarn lint:js --fix"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"eslint": "^7.32.0 || ^8.52.0",
|
|
34
34
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
35
35
|
"eslint-plugin-import": "^2.29.0",
|
|
36
|
-
"parcel": "^2.10.
|
|
36
|
+
"parcel": "^2.10.2",
|
|
37
37
|
"postcss-html": "^1.5.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
package/src/index.html
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
pointer-events: none;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
marquee-content > * {
|
|
45
45
|
will-change: transform;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -141,6 +141,10 @@
|
|
|
141
141
|
|
|
142
142
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
|
143
143
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
|
|
144
|
-
<script type="module" src="
|
|
144
|
+
<script type="module" src="index.js"></script>
|
|
145
|
+
<script>
|
|
146
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
147
|
+
MarqueeContent.registerGSAP(gsap);
|
|
148
|
+
</script>
|
|
145
149
|
</body>
|
|
146
150
|
</html>
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import breakpoints from './utils/breakpoints';
|
|
2
|
+
import cloning from './utils/cloning';
|
|
3
|
+
import skewed from './utils/skewed';
|
|
4
|
+
import animation from './utils/animation';
|
|
5
|
+
import clearTimeline from './utils/clearTimeline';
|
|
6
|
+
|
|
1
7
|
export default class MarqueeContent extends HTMLElement {
|
|
2
8
|
constructor() {
|
|
3
9
|
super();
|
|
@@ -23,148 +29,41 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
23
29
|
};
|
|
24
30
|
};
|
|
25
31
|
|
|
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)`;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
templates() {
|
|
37
|
-
const wrapper = document.createElement('div');
|
|
38
|
-
wrapper.classList.add('marquee-wrapper');
|
|
39
|
-
|
|
40
|
-
const inner = document.createElement('div');
|
|
41
|
-
inner.classList.add('marquee-inner');
|
|
42
|
-
inner.style.display = 'inline-block';
|
|
43
|
-
inner.style.whiteSpace = 'nowrap';
|
|
44
|
-
|
|
45
|
-
while (this.firstChild) {
|
|
46
|
-
inner.appendChild(this.firstChild);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
wrapper.appendChild(inner);
|
|
50
|
-
this.appendChild(wrapper);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
cloning() {
|
|
54
|
-
const removingClones = () => {
|
|
55
|
-
while (this.childElementCount > 1) {
|
|
56
|
-
this.removeChild(this.lastChild);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
removingClones();
|
|
61
|
-
|
|
62
|
-
this.MM.add(this.breakpoint, () => {
|
|
63
|
-
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
64
|
-
|
|
65
|
-
if (this.childElementCount < requiredQuantity) {
|
|
66
|
-
const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));
|
|
67
|
-
this.append(...clones);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return removingClones;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
skewed() {
|
|
75
|
-
if (!this.dataset.mcSkew) return;
|
|
76
|
-
|
|
77
|
-
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
78
|
-
const { style } = this;
|
|
79
|
-
|
|
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)`;
|
|
84
|
-
|
|
85
|
-
return () => {
|
|
86
|
-
style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
clearTimeline() {
|
|
92
|
-
if (this.timeline) {
|
|
93
|
-
this.timeline.kill();
|
|
94
|
-
this.timeline = null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this.gsap.set(this.children, { clearProps: true });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
animation() {
|
|
101
|
-
if (this.timeline) {
|
|
102
|
-
this.clearTimeline.call(this);
|
|
103
|
-
}
|
|
104
|
-
|
|
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) => {
|
|
117
|
-
if (this.dataset.mcDirection === 'ltr') {
|
|
118
|
-
this.timeline.timeScale(-1);
|
|
119
|
-
} else if (this.dataset.mcDirection === 'auto') {
|
|
120
|
-
this.timeline.timeScale(self.direction);
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
this.timeline.totalProgress(0.5);
|
|
127
|
-
|
|
128
|
-
return () => {
|
|
129
|
-
if (this.timeline) {
|
|
130
|
-
this.clearTimeline.call(this);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
32
|
update() {
|
|
137
33
|
cancelAnimationFrame(this.af);
|
|
138
34
|
|
|
139
35
|
if (this.firstElementChild) {
|
|
140
36
|
this.af = requestAnimationFrame(() => {
|
|
141
|
-
|
|
142
|
-
|
|
37
|
+
cloning.call(this);
|
|
38
|
+
animation.call(this);
|
|
143
39
|
});
|
|
144
40
|
}
|
|
145
41
|
}
|
|
146
42
|
|
|
147
43
|
init() {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.animation();
|
|
44
|
+
breakpoints.call(this);
|
|
45
|
+
skewed.call(this);
|
|
46
|
+
cloning.call(this);
|
|
47
|
+
animation.call(this);
|
|
153
48
|
}
|
|
154
49
|
|
|
155
|
-
|
|
156
|
-
this.init();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
disconnectedCallback() {
|
|
50
|
+
destroy() {
|
|
160
51
|
cancelAnimationFrame(this.af);
|
|
161
52
|
|
|
162
|
-
|
|
53
|
+
clearTimeline.call(this);
|
|
163
54
|
|
|
164
55
|
if (this.resizeObserver) {
|
|
165
56
|
this.resizeObserver.disconnect();
|
|
166
57
|
}
|
|
167
58
|
}
|
|
59
|
+
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
this.init();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
this.destroy();
|
|
66
|
+
}
|
|
168
67
|
}
|
|
169
68
|
|
|
170
69
|
if (!customElements.get('marquee-content')) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import clearTimeline from './clearTimeline';
|
|
2
|
+
|
|
3
|
+
function animation() {
|
|
4
|
+
if (this.timeline) {
|
|
5
|
+
clearTimeline.call(this);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
this.MM.add(this.breakpoint, () => {
|
|
9
|
+
this.timeline = this.gsap.to(this.children, {
|
|
10
|
+
duration: this.dataset.mcDuration || 20,
|
|
11
|
+
x: '-100%',
|
|
12
|
+
repeat: -1,
|
|
13
|
+
ease: 'none',
|
|
14
|
+
scrollTrigger: {
|
|
15
|
+
trigger: this,
|
|
16
|
+
start: 'top bottom',
|
|
17
|
+
end: 'bottom top',
|
|
18
|
+
toggleActions: 'resume pause resume pause',
|
|
19
|
+
onUpdate: (self) => {
|
|
20
|
+
if (this.dataset.mcDirection === 'ltr') {
|
|
21
|
+
this.timeline.timeScale(-1);
|
|
22
|
+
} else if (this.dataset.mcDirection === 'auto') {
|
|
23
|
+
this.timeline.timeScale(self.direction);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
this.timeline.totalProgress(0.5);
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
if (this.timeline) {
|
|
33
|
+
clearTimeline.call(this);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default animation;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function breakpoints() {
|
|
2
|
+
this.breakpoint = '';
|
|
3
|
+
|
|
4
|
+
if (this.dataset.mcMax) {
|
|
5
|
+
this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
6
|
+
} else if (this.dataset.mcMin) {
|
|
7
|
+
this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default breakpoints;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function cloning() {
|
|
2
|
+
const removingClones = () => {
|
|
3
|
+
while (this.childElementCount > 1) {
|
|
4
|
+
this.removeChild(this.lastChild);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
removingClones();
|
|
9
|
+
|
|
10
|
+
this.MM.add(this.breakpoint, () => {
|
|
11
|
+
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
12
|
+
|
|
13
|
+
if (this.childElementCount < requiredQuantity) {
|
|
14
|
+
const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));
|
|
15
|
+
this.append(...clones);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return removingClones;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default cloning;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function skewed() {
|
|
2
|
+
if (!this.dataset.mcSkew) return;
|
|
3
|
+
|
|
4
|
+
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
5
|
+
const { style } = this;
|
|
6
|
+
|
|
7
|
+
this.MM.add(this.breakpoint, () => {
|
|
8
|
+
style.transformOrigin = 'center center';
|
|
9
|
+
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
10
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
11
|
+
|
|
12
|
+
return () => {
|
|
13
|
+
style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default skewed;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import cloning from './cloning';
|
|
2
|
+
import animation from './animation';
|
|
3
|
+
|
|
4
|
+
function update() {
|
|
5
|
+
cancelAnimationFrame(this.af);
|
|
6
|
+
|
|
7
|
+
if (this.firstElementChild) {
|
|
8
|
+
this.af = requestAnimationFrame(() => {
|
|
9
|
+
cloning.call(this);
|
|
10
|
+
animation.call(this);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default update;
|
package/src/demo.js
DELETED