marquee-content 2.4.1 → 3.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 +9 -9
- package/dist/index.js +105 -124
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +103 -124
- package/dist/index.module.js.map +1 -1
- package/package.json +21 -7
- package/src/index.html +150 -0
- package/src/index.js +58 -186
- 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 +12 -0
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
|
|
|
@@ -46,16 +46,16 @@ MarqueeContent.registerGSAP(gsap);
|
|
|
46
46
|
|
|
47
47
|
➤ **Settings**
|
|
48
48
|
|
|
49
|
-
|
|
|
50
|
-
|
|
51
|
-
| `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals.
|
|
52
|
-
| `data-mc-direction` | `rtl` | `rtl` — default value, no need to specify.<br>`ltr` — changes the scroll direction from left to right.<br>`auto` —
|
|
53
|
-
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (
|
|
54
|
-
| `data-mc-min` | `null` | Sets the minimum width at which the animation will
|
|
55
|
-
| `data-mc-max` | `null` | Sets the maximum width
|
|
49
|
+
| Option | Default | Description |
|
|
50
|
+
|:--------------------|:-------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
51
|
+
| `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
|
|
52
|
+
| `data-mc-direction` | `rtl` | `rtl` — default value, no need to specify.<br>`ltr` — changes the scroll direction from left to right.<br>`auto` — auto changes the direction of the animation as the page is scrolled. |
|
|
53
|
+
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
|
|
54
|
+
| `data-mc-min` | `null` | Sets the **minimum** width at which the animation will play (when the breakpoint intersects, the cloned elements are removed and the component styles are cleared). |
|
|
55
|
+
| `data-mc-max` | `null` | Sets the **maximum** width. |
|
|
56
56
|
|
|
57
57
|
<br>
|
|
58
58
|
|
|
59
59
|
➤ **License**
|
|
60
60
|
|
|
61
|
-
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
|
}
|
|
@@ -8,6 +10,90 @@ function $parcel$export(e, n, v, s) {
|
|
|
8
10
|
$parcel$defineInteropFlag(module.exports);
|
|
9
11
|
|
|
10
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
13
|
+
function $fa2d7eec3b4b552b$var$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
|
+
var $fa2d7eec3b4b552b$export$2e2bcd8739ae039 = $fa2d7eec3b4b552b$var$breakpoints;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function $66606e06234aec1c$var$cloning() {
|
|
22
|
+
const removingClones = ()=>{
|
|
23
|
+
while(this.childElementCount > 1)this.removeChild(this.lastChild);
|
|
24
|
+
};
|
|
25
|
+
removingClones();
|
|
26
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
27
|
+
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
28
|
+
if (this.childElementCount < requiredQuantity) {
|
|
29
|
+
const clones = Array.from({
|
|
30
|
+
length: requiredQuantity - 1
|
|
31
|
+
}, ()=>this.firstElementChild.cloneNode(true));
|
|
32
|
+
this.append(...clones);
|
|
33
|
+
}
|
|
34
|
+
return removingClones;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var $66606e06234aec1c$export$2e2bcd8739ae039 = $66606e06234aec1c$var$cloning;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
function $8ce6f1187c98529f$var$skewed() {
|
|
41
|
+
if (!this.dataset.mcSkew) return;
|
|
42
|
+
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
43
|
+
const { style: style } = this;
|
|
44
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
45
|
+
style.transformOrigin = "center center";
|
|
46
|
+
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
47
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
48
|
+
return ()=>{
|
|
49
|
+
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var $8ce6f1187c98529f$export$2e2bcd8739ae039 = $8ce6f1187c98529f$var$skewed;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function $26261098b528e5f4$var$clearTimeline() {
|
|
57
|
+
if (this.timeline) {
|
|
58
|
+
this.timeline.kill();
|
|
59
|
+
this.timeline = null;
|
|
60
|
+
}
|
|
61
|
+
this.gsap.set(this.children, {
|
|
62
|
+
clearProps: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
var $26261098b528e5f4$export$2e2bcd8739ae039 = $26261098b528e5f4$var$clearTimeline;
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function $7206b27cbeabecb6$var$animation() {
|
|
69
|
+
if (this.timeline) (0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
70
|
+
this.MM.add(this.breakpoint, ()=>{
|
|
71
|
+
this.timeline = this.gsap.to(this.children, {
|
|
72
|
+
duration: this.dataset.mcDuration || 20,
|
|
73
|
+
x: "-100%",
|
|
74
|
+
repeat: -1,
|
|
75
|
+
ease: "none",
|
|
76
|
+
scrollTrigger: {
|
|
77
|
+
trigger: this,
|
|
78
|
+
start: "-=50% bottom",
|
|
79
|
+
end: "bottom top",
|
|
80
|
+
toggleActions: "resume pause resume pause",
|
|
81
|
+
onUpdate: (self)=>{
|
|
82
|
+
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
83
|
+
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.timeline.totalProgress(0.5);
|
|
88
|
+
return ()=>{
|
|
89
|
+
if (this.timeline) (0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
var $7206b27cbeabecb6$export$2e2bcd8739ae039 = $7206b27cbeabecb6$var$animation;
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
11
97
|
class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
12
98
|
constructor(){
|
|
13
99
|
super();
|
|
@@ -15,147 +101,42 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
15
101
|
this.MM = this.gsap.matchMedia();
|
|
16
102
|
this.timeline = null;
|
|
17
103
|
this.update = this.update.bind(this);
|
|
18
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)
|
|
104
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
19
105
|
this.resizeObserver.observe(this);
|
|
20
106
|
}
|
|
21
107
|
static registerGSAP(gsap) {
|
|
22
108
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
23
109
|
}
|
|
24
|
-
debounce(
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
110
|
+
debounce = ()=>{
|
|
111
|
+
let timer;
|
|
112
|
+
return ()=>{
|
|
113
|
+
cancelAnimationFrame(timer);
|
|
114
|
+
timer = requestAnimationFrame(this.update);
|
|
29
115
|
};
|
|
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
|
-
}
|
|
36
|
-
templates() {
|
|
37
|
-
const wrapper = document.createElement("div");
|
|
38
|
-
wrapper.classList.add("marquee-wrapper");
|
|
39
|
-
const inner = document.createElement("div");
|
|
40
|
-
inner.classList.add("marquee-inner");
|
|
41
|
-
inner.style.display = "inline-block";
|
|
42
|
-
inner.style.whiteSpace = "nowrap";
|
|
43
|
-
while(this.firstChild)inner.appendChild(this.firstChild);
|
|
44
|
-
wrapper.appendChild(inner);
|
|
45
|
-
this.appendChild(wrapper);
|
|
46
|
-
}
|
|
47
|
-
cloning() {
|
|
48
|
-
const removingClones = ()=>{
|
|
49
|
-
while(this.childElementCount > 1)this.removeChild(this.lastChild);
|
|
50
|
-
};
|
|
51
|
-
removingClones();
|
|
52
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
53
|
-
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
54
|
-
if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i += 1){
|
|
55
|
-
const cloned = this.firstElementChild;
|
|
56
|
-
const clone = cloned.cloneNode(true);
|
|
57
|
-
cloned.parentNode.append(clone);
|
|
58
|
-
}
|
|
59
|
-
return ()=>{
|
|
60
|
-
removingClones();
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
skewed() {
|
|
65
|
-
if (!this.dataset.mcSkew) return;
|
|
66
|
-
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
67
|
-
const { style: style } = this;
|
|
68
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
69
|
-
style.transformOrigin = "center center";
|
|
70
|
-
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
71
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
72
|
-
return ()=>{
|
|
73
|
-
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
animation() {
|
|
78
|
-
if (this.timeline) {
|
|
79
|
-
this.timeline.kill();
|
|
80
|
-
this.timeline = null;
|
|
81
|
-
}
|
|
82
|
-
this.gsap.set(this.children, {
|
|
83
|
-
clearProps: true
|
|
84
|
-
});
|
|
85
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
86
|
-
this.timeline = this.gsap.to(this.children, {
|
|
87
|
-
duration: this.dataset.mcDuration || 20,
|
|
88
|
-
x: "-100%",
|
|
89
|
-
ease: "none",
|
|
90
|
-
repeat: -1,
|
|
91
|
-
scrollTrigger: {
|
|
92
|
-
trigger: this,
|
|
93
|
-
start: "-=50% bottom",
|
|
94
|
-
end: "bottom top",
|
|
95
|
-
toggleActions: "resume pause resume pause"
|
|
96
|
-
}
|
|
97
|
-
}).totalProgress(0.5);
|
|
98
|
-
const ltrDirection = ()=>{
|
|
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;
|
|
115
|
-
}
|
|
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
|
-
}
|
|
130
|
-
this.gsap.set(this.children, {
|
|
131
|
-
clearProps: true
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
}
|
|
116
|
+
};
|
|
136
117
|
update() {
|
|
137
118
|
cancelAnimationFrame(this.af);
|
|
138
119
|
if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
(0, $66606e06234aec1c$export$2e2bcd8739ae039).call(this);
|
|
121
|
+
(0, $7206b27cbeabecb6$export$2e2bcd8739ae039).call(this);
|
|
141
122
|
});
|
|
142
123
|
}
|
|
143
124
|
init() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
125
|
+
(0, $fa2d7eec3b4b552b$export$2e2bcd8739ae039).call(this);
|
|
126
|
+
(0, $8ce6f1187c98529f$export$2e2bcd8739ae039).call(this);
|
|
127
|
+
(0, $66606e06234aec1c$export$2e2bcd8739ae039).call(this);
|
|
128
|
+
(0, $7206b27cbeabecb6$export$2e2bcd8739ae039).call(this);
|
|
129
|
+
}
|
|
130
|
+
destroy() {
|
|
131
|
+
cancelAnimationFrame(this.af);
|
|
132
|
+
(0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
133
|
+
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
149
134
|
}
|
|
150
135
|
connectedCallback() {
|
|
151
136
|
this.init();
|
|
152
137
|
}
|
|
153
138
|
disconnectedCallback() {
|
|
154
|
-
|
|
155
|
-
if (this.timeline) {
|
|
156
|
-
this.timeline.kill();
|
|
157
|
-
this.timeline = null;
|
|
158
|
-
}
|
|
139
|
+
this.destroy();
|
|
159
140
|
}
|
|
160
141
|
}
|
|
161
142
|
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
|
package/dist/index.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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WAAW;QACT,IAAI;QAEJ,OAAO;YACL,qBAAqB;YACrB,QAAQ,sBAAsB,IAAI,CAAC,MAAM;QAC3C;IACF,EAAE;IAEF,SAAS;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACxB,IAAI,CAAC,EAAE,GAAG,sBAAsB;YAC9B,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;YACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;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.js.map"}
|
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();
|
|
@@ -5,147 +89,42 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
5
89
|
this.MM = this.gsap.matchMedia();
|
|
6
90
|
this.timeline = null;
|
|
7
91
|
this.update = this.update.bind(this);
|
|
8
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)
|
|
92
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
9
93
|
this.resizeObserver.observe(this);
|
|
10
94
|
}
|
|
11
95
|
static registerGSAP(gsap) {
|
|
12
96
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
13
97
|
}
|
|
14
|
-
debounce(
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
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
|
-
}
|
|
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);
|
|
98
|
+
debounce = ()=>{
|
|
99
|
+
let timer;
|
|
100
|
+
return ()=>{
|
|
101
|
+
cancelAnimationFrame(timer);
|
|
102
|
+
timer = requestAnimationFrame(this.update);
|
|
40
103
|
};
|
|
41
|
-
|
|
42
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
43
|
-
const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
|
|
44
|
-
if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i += 1){
|
|
45
|
-
const cloned = this.firstElementChild;
|
|
46
|
-
const clone = cloned.cloneNode(true);
|
|
47
|
-
cloned.parentNode.append(clone);
|
|
48
|
-
}
|
|
49
|
-
return ()=>{
|
|
50
|
-
removingClones();
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
skewed() {
|
|
55
|
-
if (!this.dataset.mcSkew) return;
|
|
56
|
-
const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
|
|
57
|
-
const { style: style } = this;
|
|
58
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
59
|
-
style.transformOrigin = "center center";
|
|
60
|
-
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
61
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
62
|
-
return ()=>{
|
|
63
|
-
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
animation() {
|
|
68
|
-
if (this.timeline) {
|
|
69
|
-
this.timeline.kill();
|
|
70
|
-
this.timeline = null;
|
|
71
|
-
}
|
|
72
|
-
this.gsap.set(this.children, {
|
|
73
|
-
clearProps: true
|
|
74
|
-
});
|
|
75
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
76
|
-
this.timeline = this.gsap.to(this.children, {
|
|
77
|
-
duration: this.dataset.mcDuration || 20,
|
|
78
|
-
x: "-100%",
|
|
79
|
-
ease: "none",
|
|
80
|
-
repeat: -1,
|
|
81
|
-
scrollTrigger: {
|
|
82
|
-
trigger: this,
|
|
83
|
-
start: "-=50% bottom",
|
|
84
|
-
end: "bottom top",
|
|
85
|
-
toggleActions: "resume pause resume pause"
|
|
86
|
-
}
|
|
87
|
-
}).totalProgress(0.5);
|
|
88
|
-
const ltrDirection = ()=>{
|
|
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;
|
|
105
|
-
}
|
|
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
|
-
}
|
|
120
|
-
this.gsap.set(this.children, {
|
|
121
|
-
clearProps: true
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
}
|
|
104
|
+
};
|
|
126
105
|
update() {
|
|
127
106
|
cancelAnimationFrame(this.af);
|
|
128
107
|
if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
|
|
129
|
-
|
|
130
|
-
|
|
108
|
+
(0, $2b68722c48061d80$export$2e2bcd8739ae039).call(this);
|
|
109
|
+
(0, $5138c3f25fef74d5$export$2e2bcd8739ae039).call(this);
|
|
131
110
|
});
|
|
132
111
|
}
|
|
133
112
|
init() {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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();
|
|
139
122
|
}
|
|
140
123
|
connectedCallback() {
|
|
141
124
|
this.init();
|
|
142
125
|
}
|
|
143
126
|
disconnectedCallback() {
|
|
144
|
-
|
|
145
|
-
if (this.timeline) {
|
|
146
|
-
this.timeline.kill();
|
|
147
|
-
this.timeline = null;
|
|
148
|
-
}
|
|
127
|
+
this.destroy();
|
|
149
128
|
}
|
|
150
129
|
}
|
|
151
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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AC9B,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;YACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;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
|
+
"version": "3.1.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
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
26
|
+
"clean": "rm -rf dist .parcel-cache",
|
|
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
|
+
"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.2",
|
|
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/index.html
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
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-content > * {
|
|
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="index.js"></script>
|
|
145
|
+
<script>
|
|
146
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
147
|
+
MarqueeContent.registerGSAP(gsap);
|
|
148
|
+
</script>
|
|
149
|
+
</body>
|
|
150
|
+
</html>
|
package/src/index.js
CHANGED
|
@@ -1,199 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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), 150));
|
|
10
|
-
this.resizeObserver.observe(this);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static registerGSAP(gsap) {
|
|
14
|
-
MarqueeContent.gsap = gsap;
|
|
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
|
-
|
|
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
|
-
for (let i = 1; i < requiredQuantity; i += 1) {
|
|
67
|
-
const cloned = this.firstElementChild;
|
|
68
|
-
const clone = cloned.cloneNode(true);
|
|
69
|
-
cloned.parentNode.append(clone);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return () => {
|
|
74
|
-
removingClones();
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}
|
|
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';
|
|
78
6
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
147
|
-
if (this.dataset.mcDirection === 'ltr') {
|
|
148
|
-
ltrDirection();
|
|
149
|
-
} else if (this.dataset.mcDirection === 'auto') {
|
|
150
|
-
autoDirection();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return () => {
|
|
154
|
-
if (this.timeline) {
|
|
155
|
-
this.timeline.kill();
|
|
156
|
-
this.timeline = null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
this.gsap.set(this.children, { clearProps: true });
|
|
160
|
-
};
|
|
161
|
-
});
|
|
7
|
+
export default class MarqueeContent extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this.gsap = MarqueeContent.gsap || window.gsap;
|
|
12
|
+
this.MM = this.gsap.matchMedia();
|
|
13
|
+
this.timeline = null;
|
|
14
|
+
this.update = this.update.bind(this);
|
|
15
|
+
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
16
|
+
this.resizeObserver.observe(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static registerGSAP(gsap) {
|
|
20
|
+
MarqueeContent.gsap = gsap;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
debounce = () => {
|
|
24
|
+
let timer;
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
cancelAnimationFrame(timer);
|
|
28
|
+
timer = requestAnimationFrame(this.update);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
update() {
|
|
33
|
+
cancelAnimationFrame(this.af);
|
|
34
|
+
|
|
35
|
+
if (this.firstElementChild) {
|
|
36
|
+
this.af = requestAnimationFrame(() => {
|
|
37
|
+
cloning.call(this);
|
|
38
|
+
animation.call(this);
|
|
39
|
+
});
|
|
162
40
|
}
|
|
41
|
+
}
|
|
163
42
|
|
|
164
|
-
|
|
165
|
-
|
|
43
|
+
init() {
|
|
44
|
+
breakpoints.call(this);
|
|
45
|
+
skewed.call(this);
|
|
46
|
+
cloning.call(this);
|
|
47
|
+
animation.call(this);
|
|
48
|
+
}
|
|
166
49
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.cloning();
|
|
170
|
-
this.animation();
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
50
|
+
destroy() {
|
|
51
|
+
cancelAnimationFrame(this.af);
|
|
174
52
|
|
|
175
|
-
|
|
176
|
-
this.breakpoints();
|
|
177
|
-
this.templates();
|
|
178
|
-
this.skewed();
|
|
179
|
-
this.cloning();
|
|
180
|
-
this.animation();
|
|
181
|
-
}
|
|
53
|
+
clearTimeline.call(this);
|
|
182
54
|
|
|
183
|
-
|
|
184
|
-
|
|
55
|
+
if (this.resizeObserver) {
|
|
56
|
+
this.resizeObserver.disconnect();
|
|
185
57
|
}
|
|
58
|
+
}
|
|
186
59
|
|
|
187
|
-
|
|
188
|
-
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
this.init();
|
|
62
|
+
}
|
|
189
63
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
}
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
this.destroy();
|
|
66
|
+
}
|
|
195
67
|
}
|
|
196
68
|
|
|
197
69
|
if (!customElements.get('marquee-content')) {
|
|
198
|
-
|
|
70
|
+
customElements.define('marquee-content', MarqueeContent);
|
|
199
71
|
}
|
|
@@ -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: '-=50% 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;
|