marquee-content 3.1.0 → 4.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/LICENSE +1 -1
- package/README.md +14 -17
- package/dist/index.js +99 -115
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +97 -113
- package/dist/index.module.js.map +1 -1
- package/package.json +5 -5
- package/src/demo.js +10 -0
- package/src/index.js +46 -54
- package/src/utils.js +95 -0
- package/src/index.html +0 -150
- package/src/utils/animation.js +0 -39
- package/src/utils/breakpoints.js +0 -11
- package/src/utils/clearTimeline.js +0 -10
- package/src/utils/cloning.js +0 -22
- package/src/utils/skewed.js +0 -18
- package/src/utils/update.js +0 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
1
|
<br>
|
|
2
|
-
<p align="center"><strong>marquee-content</strong></p>
|
|
3
|
-
|
|
4
2
|
<div align="center">
|
|
5
3
|
|
|
4
|
+
# marquee-content
|
|
5
|
+
A simple, lightweight library for creating the effect of running horizontal blocks of content, also known as a marquee or ticker. Uses GSAP and Resize Observer for better performance.
|
|
6
|
+
|
|
6
7
|
[](https://www.npmjs.com/package/marquee-content)
|
|
7
8
|
[](https://github.com/ux-ui-pro/marquee-content)
|
|
8
9
|
[](https://www.npmjs.org/package/marquee-content)
|
|
9
10
|
|
|
11
|
+
<sup>1kB gzipped</sup>
|
|
12
|
+
|
|
13
|
+
### <a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a>
|
|
14
|
+
|
|
10
15
|
</div>
|
|
11
16
|
|
|
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>1kB gzipped</sup></p>
|
|
14
|
-
<p align="center"><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></p>
|
|
15
17
|
<br>
|
|
16
18
|
|
|
17
19
|
➤ **Install**
|
|
18
|
-
|
|
19
20
|
```
|
|
20
21
|
yarn add gsap
|
|
21
22
|
yarn add marquee-content
|
|
22
23
|
```
|
|
23
|
-
|
|
24
24
|
<br>
|
|
25
25
|
|
|
26
26
|
➤ **Import**
|
|
27
|
-
|
|
28
27
|
```javascript
|
|
29
|
-
import gsap from 'gsap';
|
|
28
|
+
import { gsap } from 'gsap';
|
|
30
29
|
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
|
31
30
|
import MarqueeContent from 'marquee-content';
|
|
32
|
-
|
|
33
|
-
gsap.registerPlugin(ScrollTrigger);
|
|
34
|
-
MarqueeContent.registerGSAP(gsap);
|
|
35
31
|
```
|
|
36
32
|
<br>
|
|
37
33
|
|
|
38
34
|
➤ **Usage**
|
|
35
|
+
```javascript
|
|
36
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
37
|
+
MarqueeContent.registerGSAP(gsap);
|
|
38
|
+
|
|
39
|
+
const marqueeContent = new MarqueeContent();
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
<marquee-content data-mc-duration="30" role="marquee">
|
|
42
|
-
content
|
|
43
|
-
</marquee-content>
|
|
41
|
+
marqueeContent.init();
|
|
44
42
|
```
|
|
45
43
|
<br>
|
|
46
44
|
|
|
@@ -53,7 +51,6 @@ MarqueeContent.registerGSAP(gsap);
|
|
|
53
51
|
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
|
|
54
52
|
| `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
53
|
| `data-mc-max` | `null` | Sets the **maximum** width. |
|
|
56
|
-
|
|
57
54
|
<br>
|
|
58
55
|
|
|
59
56
|
➤ **License**
|
package/dist/index.js
CHANGED
|
@@ -10,136 +10,120 @@ function $parcel$export(e, n, v, s) {
|
|
|
10
10
|
$parcel$defineInteropFlag(module.exports);
|
|
11
11
|
|
|
12
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const $4559ecf940edc78d$export$61fc7d43ac8f84b0 = function(func) {
|
|
14
|
+
let timer;
|
|
15
|
+
return (...args)=>{
|
|
16
|
+
cancelAnimationFrame(timer);
|
|
17
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const $4559ecf940edc78d$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
|
|
21
|
+
timeline?.kill();
|
|
22
|
+
timeline = gsap.timeline({
|
|
23
|
+
scrollTrigger: {
|
|
24
|
+
trigger: element,
|
|
25
|
+
start: "top bottom",
|
|
26
|
+
end: "bottom top",
|
|
27
|
+
toggleActions: "resume pause resume pause",
|
|
28
|
+
onUpdate: (self)=>{
|
|
29
|
+
if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
30
|
+
else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
35
|
+
timeline.to(element.children, {
|
|
36
|
+
duration: element.dataset.mcDuration ?? 20,
|
|
37
|
+
x: "-100%",
|
|
38
|
+
repeat: -1,
|
|
39
|
+
ease: "none"
|
|
40
|
+
});
|
|
41
|
+
timeline.totalProgress(0.5);
|
|
42
|
+
return ()=>timeline?.kill();
|
|
43
|
+
});
|
|
44
|
+
update.timeline = timeline;
|
|
45
|
+
return timeline;
|
|
46
|
+
};
|
|
47
|
+
const $4559ecf940edc78d$export$d07517a676ce386f = function(element) {
|
|
48
|
+
element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
|
|
49
|
+
};
|
|
50
|
+
const $4559ecf940edc78d$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
|
|
51
|
+
timeline?.kill();
|
|
52
|
+
timeline = null;
|
|
53
|
+
gsap.set(element.children, {
|
|
54
|
+
clearProps: "all"
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const $4559ecf940edc78d$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
|
|
22
58
|
const removingClones = ()=>{
|
|
23
|
-
while(
|
|
59
|
+
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
24
60
|
};
|
|
25
61
|
removingClones();
|
|
26
|
-
|
|
27
|
-
const requiredQuantity = Math.ceil(
|
|
28
|
-
if (
|
|
62
|
+
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
63
|
+
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
64
|
+
if (element.childElementCount < requiredQuantity) {
|
|
65
|
+
const fragment = document.createDocumentFragment();
|
|
29
66
|
const clones = Array.from({
|
|
30
67
|
length: requiredQuantity - 1
|
|
31
|
-
}, ()=>
|
|
32
|
-
|
|
68
|
+
}, ()=>element.firstElementChild.cloneNode(true));
|
|
69
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
70
|
+
element.appendChild(fragment);
|
|
33
71
|
}
|
|
34
72
|
return removingClones;
|
|
35
73
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
this
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
97
|
-
class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
98
|
-
constructor(){
|
|
99
|
-
super();
|
|
100
|
-
this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
101
|
-
this.MM = this.gsap.matchMedia();
|
|
102
|
-
this.timeline = null;
|
|
103
|
-
this.update = this.update.bind(this);
|
|
104
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
105
|
-
this.resizeObserver.observe(this);
|
|
74
|
+
};
|
|
75
|
+
const $4559ecf940edc78d$export$3484d11c6bb42ecc = function(element) {
|
|
76
|
+
if (!element.dataset.mcSkew) return;
|
|
77
|
+
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
78
|
+
const { style: style } = element;
|
|
79
|
+
style.transformOrigin = "center center";
|
|
80
|
+
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
81
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class $4fa36e821943b400$export$2e2bcd8739ae039 {
|
|
86
|
+
#gsap;
|
|
87
|
+
#MM;
|
|
88
|
+
#timeline;
|
|
89
|
+
#element;
|
|
90
|
+
#resizeObserver;
|
|
91
|
+
#animationFrame;
|
|
92
|
+
constructor(el){
|
|
93
|
+
this.#gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap ?? window.gsap;
|
|
94
|
+
this.#MM = this.#gsap.matchMedia();
|
|
95
|
+
this.#timeline = null;
|
|
96
|
+
this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
|
|
97
|
+
if (!this.#element) throw new Error("Element not found");
|
|
98
|
+
this.#resizeObserver = new ResizeObserver((0, $4559ecf940edc78d$export$61fc7d43ac8f84b0)(()=>this.#update()));
|
|
99
|
+
this.#resizeObserver.observe(this.#element);
|
|
106
100
|
}
|
|
107
101
|
static registerGSAP(gsap) {
|
|
108
102
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
#commonInit = ()=>{
|
|
105
|
+
(0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
106
|
+
(0, $4559ecf940edc78d$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
|
|
107
|
+
(0, $4559ecf940edc78d$export$d07517a676ce386f)(this.#element);
|
|
108
|
+
(0, $4559ecf940edc78d$export$3484d11c6bb42ecc)(this.#element);
|
|
109
|
+
this.#timeline = (0, $4559ecf940edc78d$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
116
110
|
};
|
|
117
|
-
update()
|
|
118
|
-
cancelAnimationFrame(this
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
111
|
+
#update = ()=>{
|
|
112
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
113
|
+
this.#animationFrame = requestAnimationFrame(()=>{
|
|
114
|
+
this.#commonInit();
|
|
115
|
+
ScrollTrigger.refresh();
|
|
122
116
|
});
|
|
123
|
-
}
|
|
124
|
-
init()
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
133
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
134
|
-
}
|
|
135
|
-
connectedCallback() {
|
|
136
|
-
this.init();
|
|
137
|
-
}
|
|
138
|
-
disconnectedCallback() {
|
|
139
|
-
this.destroy();
|
|
140
|
-
}
|
|
117
|
+
};
|
|
118
|
+
init = ()=>{
|
|
119
|
+
this.#commonInit();
|
|
120
|
+
};
|
|
121
|
+
destroy = ()=>{
|
|
122
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
123
|
+
(0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
124
|
+
this.#resizeObserver?.disconnect();
|
|
125
|
+
};
|
|
141
126
|
}
|
|
142
|
-
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
143
127
|
|
|
144
128
|
|
|
145
129
|
//# sourceMappingURL=index.js.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;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n};\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,133 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0 = function(func) {
|
|
2
|
+
let timer;
|
|
3
|
+
return (...args)=>{
|
|
4
|
+
cancelAnimationFrame(timer);
|
|
5
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
const $f3ad94c9f84f4d57$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
|
|
9
|
+
timeline?.kill();
|
|
10
|
+
timeline = gsap.timeline({
|
|
11
|
+
scrollTrigger: {
|
|
12
|
+
trigger: element,
|
|
13
|
+
start: "top bottom",
|
|
14
|
+
end: "bottom top",
|
|
15
|
+
toggleActions: "resume pause resume pause",
|
|
16
|
+
onUpdate: (self)=>{
|
|
17
|
+
if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
18
|
+
else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
23
|
+
timeline.to(element.children, {
|
|
24
|
+
duration: element.dataset.mcDuration ?? 20,
|
|
25
|
+
x: "-100%",
|
|
26
|
+
repeat: -1,
|
|
27
|
+
ease: "none"
|
|
28
|
+
});
|
|
29
|
+
timeline.totalProgress(0.5);
|
|
30
|
+
return ()=>timeline?.kill();
|
|
31
|
+
});
|
|
32
|
+
update.timeline = timeline;
|
|
33
|
+
return timeline;
|
|
34
|
+
};
|
|
35
|
+
const $f3ad94c9f84f4d57$export$d07517a676ce386f = function(element) {
|
|
36
|
+
element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
|
|
37
|
+
};
|
|
38
|
+
const $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
|
|
39
|
+
timeline?.kill();
|
|
40
|
+
timeline = null;
|
|
41
|
+
gsap.set(element.children, {
|
|
42
|
+
clearProps: "all"
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
|
|
10
46
|
const removingClones = ()=>{
|
|
11
|
-
while(
|
|
47
|
+
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
12
48
|
};
|
|
13
49
|
removingClones();
|
|
14
|
-
|
|
15
|
-
const requiredQuantity = Math.ceil(
|
|
16
|
-
if (
|
|
50
|
+
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
51
|
+
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
52
|
+
if (element.childElementCount < requiredQuantity) {
|
|
53
|
+
const fragment = document.createDocumentFragment();
|
|
17
54
|
const clones = Array.from({
|
|
18
55
|
length: requiredQuantity - 1
|
|
19
|
-
}, ()=>
|
|
20
|
-
|
|
56
|
+
}, ()=>element.firstElementChild.cloneNode(true));
|
|
57
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
58
|
+
element.appendChild(fragment);
|
|
21
59
|
}
|
|
22
60
|
return removingClones;
|
|
23
61
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
|
62
|
+
};
|
|
63
|
+
const $f3ad94c9f84f4d57$export$3484d11c6bb42ecc = function(element) {
|
|
64
|
+
if (!element.dataset.mcSkew) return;
|
|
65
|
+
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
66
|
+
const { style: style } = element;
|
|
67
|
+
style.transformOrigin = "center center";
|
|
68
|
+
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
69
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
70
|
+
};
|
|
42
71
|
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
85
|
-
class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
86
|
-
constructor(){
|
|
87
|
-
super();
|
|
88
|
-
this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
89
|
-
this.MM = this.gsap.matchMedia();
|
|
90
|
-
this.timeline = null;
|
|
91
|
-
this.update = this.update.bind(this);
|
|
92
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
93
|
-
this.resizeObserver.observe(this);
|
|
73
|
+
class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
|
|
74
|
+
#gsap;
|
|
75
|
+
#MM;
|
|
76
|
+
#timeline;
|
|
77
|
+
#element;
|
|
78
|
+
#resizeObserver;
|
|
79
|
+
#animationFrame;
|
|
80
|
+
constructor(el){
|
|
81
|
+
this.#gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap ?? window.gsap;
|
|
82
|
+
this.#MM = this.#gsap.matchMedia();
|
|
83
|
+
this.#timeline = null;
|
|
84
|
+
this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
|
|
85
|
+
if (!this.#element) throw new Error("Element not found");
|
|
86
|
+
this.#resizeObserver = new ResizeObserver((0, $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0)(()=>this.#update()));
|
|
87
|
+
this.#resizeObserver.observe(this.#element);
|
|
94
88
|
}
|
|
95
89
|
static registerGSAP(gsap) {
|
|
96
90
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
#commonInit = ()=>{
|
|
93
|
+
(0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
94
|
+
(0, $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
|
|
95
|
+
(0, $f3ad94c9f84f4d57$export$d07517a676ce386f)(this.#element);
|
|
96
|
+
(0, $f3ad94c9f84f4d57$export$3484d11c6bb42ecc)(this.#element);
|
|
97
|
+
this.#timeline = (0, $f3ad94c9f84f4d57$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
104
98
|
};
|
|
105
|
-
update()
|
|
106
|
-
cancelAnimationFrame(this
|
|
107
|
-
|
|
108
|
-
(
|
|
109
|
-
|
|
99
|
+
#update = ()=>{
|
|
100
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
101
|
+
this.#animationFrame = requestAnimationFrame(()=>{
|
|
102
|
+
this.#commonInit();
|
|
103
|
+
ScrollTrigger.refresh();
|
|
110
104
|
});
|
|
111
|
-
}
|
|
112
|
-
init()
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
(0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
121
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
122
|
-
}
|
|
123
|
-
connectedCallback() {
|
|
124
|
-
this.init();
|
|
125
|
-
}
|
|
126
|
-
disconnectedCallback() {
|
|
127
|
-
this.destroy();
|
|
128
|
-
}
|
|
105
|
+
};
|
|
106
|
+
init = ()=>{
|
|
107
|
+
this.#commonInit();
|
|
108
|
+
};
|
|
109
|
+
destroy = ()=>{
|
|
110
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
111
|
+
(0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
112
|
+
this.#resizeObserver?.disconnect();
|
|
113
|
+
};
|
|
129
114
|
}
|
|
130
|
-
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
|
|
131
115
|
|
|
132
116
|
|
|
133
117
|
export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"ACAO,MAAM,4CAAW,SAAS,IAAI;IACnC,IAAI;IAEJ,OAAO,CAAC,GAAG;QACT,qBAAqB;QAErB,QAAQ,sBAAsB,IAAM,QAAQ;IAC9C;AACF;AAEO,MAAM,4CAAY,SAAS,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM;IACnE,UAAU;IAEV,WAAW,KAAK,QAAQ,CAAC;QACvB,eAAe;YACb,SAAS;YACT,OAAO;YACP,KAAK;YACL,eAAe;YACf,UAAU,CAAC;gBACT,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,OAClC,SAAS,SAAS,CAAC;qBACd,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,QACzC,SAAS,SAAS,CAAC,KAAK,SAAS;YAErC;QACF;IACF;IAEA,GAAG,GAAG,CAAC,QAAQ,OAAO,CAAC,YAAY,EAAE;QACnC,SAAS,EAAE,CAAC,QAAQ,QAAQ,EAAE;YAC5B,UAAU,QAAQ,OAAO,CAAC,UAAU,IAAI;YACxC,GAAG;YACH,QAAQ;YACR,MAAM;QACR;QAEA,SAAS,aAAa,CAAC;QAEvB,OAAO,IAAM,UAAU;IACzB;IAEA,OAAO,QAAQ,GAAG;IAElB,OAAO;AACT;AAEO,MAAM,4CAAc,SAAS,OAAO;IACzC,QAAQ,OAAO,CAAC,YAAY,GAAG,QAAQ,OAAO,CAAC,KAAK,GAChD,CAAC,YAA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,QAAQ,GAAG,CAAA,GAAA,yCAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IACtF,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\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": "4.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",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"lintfix": "yarn lint:js --fix"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"eslint": "^
|
|
33
|
+
"eslint": "^8.57.0",
|
|
34
34
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
35
|
-
"eslint-plugin-import": "^2.29.
|
|
36
|
-
"parcel": "^2.
|
|
37
|
-
"postcss-html": "^1.
|
|
35
|
+
"eslint-plugin-import": "^2.29.1",
|
|
36
|
+
"parcel": "^2.12.0",
|
|
37
|
+
"postcss-html": "^1.6.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"marquee",
|
package/src/demo.js
ADDED
package/src/index.js
CHANGED
|
@@ -1,71 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
debounce,
|
|
3
|
+
breakpoints,
|
|
4
|
+
cloning,
|
|
5
|
+
skewed,
|
|
6
|
+
animation,
|
|
7
|
+
clearTimeline,
|
|
8
|
+
} from './utils.js';
|
|
6
9
|
|
|
7
|
-
export default class MarqueeContent
|
|
8
|
-
|
|
9
|
-
super();
|
|
10
|
+
export default class MarqueeContent {
|
|
11
|
+
#gsap;
|
|
10
12
|
|
|
11
|
-
|
|
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
|
-
}
|
|
13
|
+
#MM;
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
MarqueeContent.gsap = gsap;
|
|
21
|
-
}
|
|
15
|
+
#timeline;
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
let timer;
|
|
17
|
+
#element;
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
cancelAnimationFrame(timer);
|
|
28
|
-
timer = requestAnimationFrame(this.update);
|
|
29
|
-
};
|
|
30
|
-
};
|
|
19
|
+
#resizeObserver;
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
cancelAnimationFrame(this.af);
|
|
21
|
+
#animationFrame;
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
23
|
+
constructor(el) {
|
|
24
|
+
this.#gsap = MarqueeContent.gsap ?? window.gsap;
|
|
25
|
+
this.#MM = this.#gsap.matchMedia();
|
|
26
|
+
this.#timeline = null;
|
|
27
|
+
this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');
|
|
28
|
+
if (!this.#element) throw new Error('Element not found');
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
skewed.call(this);
|
|
46
|
-
cloning.call(this);
|
|
47
|
-
animation.call(this);
|
|
30
|
+
this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));
|
|
31
|
+
this.#resizeObserver.observe(this.#element);
|
|
48
32
|
}
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
static registerGSAP(gsap) {
|
|
35
|
+
MarqueeContent.gsap = gsap;
|
|
36
|
+
}
|
|
52
37
|
|
|
53
|
-
|
|
38
|
+
#commonInit = () => {
|
|
39
|
+
clearTimeline(this.#timeline, this.#element, this.#gsap);
|
|
40
|
+
cloning(this.#element, this.#gsap, this.#MM);
|
|
41
|
+
breakpoints(this.#element);
|
|
42
|
+
skewed(this.#element);
|
|
43
|
+
this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
44
|
+
};
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
#update = () => {
|
|
47
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
48
|
+
this.#animationFrame = requestAnimationFrame(() => {
|
|
49
|
+
this.#commonInit();
|
|
50
|
+
ScrollTrigger.refresh();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
this
|
|
54
|
+
init = () => {
|
|
55
|
+
this.#commonInit();
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
this
|
|
58
|
+
destroy = () => {
|
|
59
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
60
|
+
clearTimeline(this.#timeline, this.#element, this.#gsap);
|
|
61
|
+
this.#resizeObserver?.disconnect();
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
if (!customElements.get('marquee-content')) {
|
|
70
|
-
customElements.define('marquee-content', MarqueeContent);
|
|
71
|
-
}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const debounce = function(func) {
|
|
2
|
+
let timer;
|
|
3
|
+
|
|
4
|
+
return (...args) => {
|
|
5
|
+
cancelAnimationFrame(timer);
|
|
6
|
+
|
|
7
|
+
timer = requestAnimationFrame(() => func(...args));
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const animation = function(element, gsap, MM, timeline, update) {
|
|
12
|
+
timeline?.kill();
|
|
13
|
+
|
|
14
|
+
timeline = gsap.timeline({
|
|
15
|
+
scrollTrigger: {
|
|
16
|
+
trigger: element,
|
|
17
|
+
start: 'top bottom',
|
|
18
|
+
end: 'bottom top',
|
|
19
|
+
toggleActions: 'resume pause resume pause',
|
|
20
|
+
onUpdate: (self) => {
|
|
21
|
+
if (element.dataset.mcDirection === 'ltr') {
|
|
22
|
+
timeline.timeScale(-1);
|
|
23
|
+
} else if (element.dataset.mcDirection === 'auto') {
|
|
24
|
+
timeline.timeScale(self.direction);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
MM.add(element.dataset.mcBreakpoint, () => {
|
|
31
|
+
timeline.to(element.children, {
|
|
32
|
+
duration: element.dataset.mcDuration ?? 20,
|
|
33
|
+
x: '-100%',
|
|
34
|
+
repeat: -1,
|
|
35
|
+
ease: 'none',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
timeline.totalProgress(0.5);
|
|
39
|
+
|
|
40
|
+
return () => timeline?.kill();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
update.timeline = timeline;
|
|
44
|
+
|
|
45
|
+
return timeline;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const breakpoints = function(element) {
|
|
49
|
+
element.dataset.mcBreakpoint = element.dataset.mcMax
|
|
50
|
+
? `(max-width: ${element.dataset.mcMax - 0.02}px)`
|
|
51
|
+
: element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const clearTimeline = function(timeline, element, gsap) {
|
|
55
|
+
timeline?.kill();
|
|
56
|
+
timeline = null;
|
|
57
|
+
|
|
58
|
+
gsap.set(element.children, { clearProps: 'all' });
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const cloning = function(element, gsap, MM) {
|
|
62
|
+
const removingClones = () => {
|
|
63
|
+
while (element.childElementCount > 1) {
|
|
64
|
+
element.removeChild(element.lastChild);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
removingClones();
|
|
69
|
+
|
|
70
|
+
MM.add(element.dataset.mcBreakpoint, () => {
|
|
71
|
+
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
72
|
+
|
|
73
|
+
if (element.childElementCount < requiredQuantity) {
|
|
74
|
+
const fragment = document.createDocumentFragment();
|
|
75
|
+
const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));
|
|
76
|
+
|
|
77
|
+
clones.forEach(clone => fragment.appendChild(clone));
|
|
78
|
+
|
|
79
|
+
element.appendChild(fragment);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return removingClones;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const skewed = function(element) {
|
|
87
|
+
if (!element.dataset.mcSkew) return;
|
|
88
|
+
|
|
89
|
+
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
90
|
+
const { style } = element;
|
|
91
|
+
|
|
92
|
+
style.transformOrigin = 'center center';
|
|
93
|
+
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
94
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
95
|
+
};
|
package/src/index.html
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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/utils/animation.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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;
|
package/src/utils/breakpoints.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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;
|
package/src/utils/cloning.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
package/src/utils/skewed.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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;
|