marquee-content 2.1.2 → 2.3.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 CHANGED
@@ -1,41 +1,46 @@
1
- <div align="center">
2
1
  <br>
2
+ <p align="center"><strong>marquee-content</strong></p>
3
3
 
4
- <h1>marquee-content</h1>
4
+ <div align="center">
5
5
 
6
6
  [![npm](https://img.shields.io/npm/v/marquee-content.svg?colorB=brightgreen)](https://www.npmjs.com/package/marquee-content)
7
7
  [![GitHub package version](https://img.shields.io/github/package-json/v/ux-ui-pro/marquee-content.svg)](https://github.com/ux-ui-pro/marquee-content)
8
8
  [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.org/package/marquee-content)
9
9
 
10
- <p>A simple library for creating the running content effect, also known as marquee or ticker.<br>The library uses GSAP and Resize Observer to achieve the best performance results.</p>
11
- <p><sup>1.2kB gzipped</sup></p>
12
- <h3><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></h3>
13
-
14
10
  </div>
11
+
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>1.2kB gzipped</sup></p>
14
+ <p align="center"><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></p>
15
15
  <br>
16
16
 
17
- ### Installation
17
+ &#10148; **Install**
18
+
18
19
  ```
19
- $ yarn add gsap
20
- $ yarn add marquee-content
20
+ yarn add gsap
21
+ yarn add marquee-content
21
22
  ```
22
23
 
23
24
  <br>
24
25
 
25
- ### Import
26
+ &#10148; **Import**
27
+
26
28
  ```javascript
27
- import { gsap } from 'gsap'
28
- import { ScrollTrigger } from 'gsap/ScrollTrigger'
29
- import MarqueeContent from 'marquee-content'
29
+ import gsap from 'gsap';
30
+ import { ScrollTrigger } from 'gsap/ScrollTrigger';
31
+ import MarqueeContent from 'marquee-content';
32
+
33
+ gsap.registerPlugin(ScrollTrigger);
34
+ MarqueeContent.registerGSAP(gsap);
30
35
 
31
- gsap.registerPlugin(ScrollTrigger)
32
- MarqueeContent.registerGSAP(gsap)
36
+ const marqueeContent = new MarqueeContent();
33
37
 
34
- new MarqueeContent()
38
+ marqueeContent.init();
35
39
  ```
36
40
  <br>
37
41
 
38
- ### Usage
42
+ &#10148; **Usage**
43
+
39
44
  ```HTML
40
45
  <marquee-content data-mc-duration="30" role="marquee">
41
46
  content
@@ -43,17 +48,18 @@ new MarqueeContent()
43
48
  ```
44
49
  <br>
45
50
 
46
- ### Settings
51
+ &#10148; **Settings**
47
52
 
48
- | data-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Default | Description |
49
- | --- | --- | --- |
50
- | `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
51
- | `data-mc-direction` | `rtl` | `rtl` &mdash; default value, no need to specify.<br>`ltr` &mdash; changes the scroll direction from left to right.<br>`auto` &mdash; automatically changes the direction of the animation when scrolling the page. |
52
- | `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value). |
53
- | `data-mc-min` | `null` | Sets the minimum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
54
- | `data-mc-max` | `null` | Sets the maximum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
53
+ | data- | Default | Description |
54
+ |:--------------------|:-------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
+ | `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
56
+ | `data-mc-direction` | `rtl` | `rtl` &mdash; default value, no need to specify.<br>`ltr` &mdash; changes the scroll direction from left to right.<br>`auto` &mdash; automatically changes the direction of the animation when scrolling the page. |
57
+ | `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value). |
58
+ | `data-mc-min` | `null` | Sets the minimum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
59
+ | `data-mc-max` | `null` | Sets the maximum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
55
60
 
56
61
  <br>
57
62
 
58
- ### License
59
- Marquee-content is released under MIT license.
63
+ &#10148; **License**
64
+
65
+ marquee-content is released under MIT license.
package/dist/index.js CHANGED
@@ -13,7 +13,6 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
13
13
  super();
14
14
  this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
15
15
  this.MM = this.gsap.matchMedia();
16
- this.breakpoint = this.dataset.mcMax ? `(max-width: ${this.dataset.mcMax - 0.02}px)` : this.dataset.mcMin ? `(min-width: ${this.dataset.mcMin}px)` : "";
17
16
  this.update = this.update.bind(this);
18
17
  this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
19
18
  this.resizeObserver.observe(this);
@@ -21,11 +20,16 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
21
20
  static registerGSAP(gsap) {
22
21
  $4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
23
22
  }
23
+ breakpoints() {
24
+ this.breakpoint = "";
25
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
26
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
27
+ }
24
28
  debounce(fn, delay) {
25
- let timer;
29
+ this.timer = null;
26
30
  return (...args)=>{
27
- if (timer) clearTimeout(timer);
28
- timer = setTimeout(()=>fn(...args), delay);
31
+ if (this.timer) clearTimeout(this.timer);
32
+ this.timer = setTimeout(()=>fn(...args), delay);
29
33
  };
30
34
  }
31
35
  templates() {
@@ -45,10 +49,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
45
49
  };
46
50
  removingClones();
47
51
  this.MM.add(this.breakpoint, ()=>{
48
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
49
- if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
50
- let cloned = this.firstElementChild;
51
- let clone = cloned.cloneNode(true);
52
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
53
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i += 1){
54
+ const cloned = this.firstElementChild;
55
+ const clone = cloned.cloneNode(true);
52
56
  cloned.parentNode.append(clone);
53
57
  }
54
58
  return ()=>{
@@ -58,8 +62,8 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
58
62
  }
59
63
  skewed() {
60
64
  if (!this.dataset.mcSkew) return;
61
- const abs = Math.abs(parseInt(this.dataset.mcSkew));
62
- const style = this.style;
65
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
66
+ const { style: style } = this;
63
67
  this.MM.add(this.breakpoint, ()=>{
64
68
  style.transformOrigin = "center center";
65
69
  style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
@@ -70,16 +74,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
70
74
  });
71
75
  }
72
76
  animation() {
73
- let timeLine = this.gsap.timeline();
74
- timeLine.kill();
75
- timeLine = null;
76
77
  this.gsap.set(this.children, {
77
78
  clearProps: true
78
79
  });
79
80
  this.MM.add(this.breakpoint, ()=>{
80
- this.gsap.set(this.children, {
81
- "will-change": "transform"
82
- });
83
81
  const tween = this.gsap.to(this.children, {
84
82
  duration: this.dataset.mcDuration || 20,
85
83
  x: "-100%",
@@ -99,9 +97,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
99
97
  });
100
98
  };
101
99
  const autoDirection = ()=>{
102
- let currentScroll = 0, scrollDirection = 1;
100
+ let currentScroll = 0;
101
+ let scrollDirection = 1;
103
102
  const handleScroll = ()=>{
104
- let orientation = window.pageYOffset > currentScroll ? 1 : -1;
103
+ const orientation = window.scrollY > currentScroll ? 1 : -1;
105
104
  if (orientation !== scrollDirection) {
106
105
  this.gsap.to(tween, {
107
106
  timeScale: orientation,
@@ -109,16 +108,15 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
109
108
  });
110
109
  scrollDirection = orientation;
111
110
  }
112
- currentScroll = window.pageYOffset;
111
+ currentScroll = window.scrollY;
113
112
  };
114
- addEventListener("scroll", ()=>{
115
- handleScroll();
116
- }, {
113
+ window.addEventListener("scroll", handleScroll, {
117
114
  capture: true,
118
115
  passive: true
119
116
  });
120
117
  };
121
- this.dataset.mcDirection === "ltr" ? ltrDirection() : this.dataset.mcDirection === "auto" && autoDirection();
118
+ if (this.dataset.mcDirection === "ltr") ltrDirection();
119
+ else if (this.dataset.mcDirection === "auto") autoDirection();
122
120
  return ()=>{
123
121
  this.gsap.set(this.children, {
124
122
  clearProps: true
@@ -133,17 +131,21 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
133
131
  this.animation();
134
132
  });
135
133
  }
136
- connectedCallback() {
134
+ init() {
135
+ this.breakpoints();
137
136
  this.templates();
138
137
  this.skewed();
139
138
  this.cloning();
140
139
  this.animation();
141
140
  }
141
+ connectedCallback() {
142
+ this.init();
143
+ }
142
144
  disconnectedCallback() {
143
145
  cancelAnimationFrame(this.af);
144
146
  }
145
147
  }
146
- customElements.get("marquee-content") || customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
148
+ if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
147
149
 
148
150
 
149
151
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1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W;oBACX,WAAW;gBACf;YACJ;YAEA,MAAM,gBAAgB;gBAClB,IAAI,gBAAgB,GAChB,kBAAkB;gBAEtB,MAAM,eAAe;oBACjB,IAAI,cAAc,AAAC,OAAO,cAAc,gBAAiB,IAAI;oBAE7D,IAAI,gBAAgB,iBAAiB;wBACjC,IAAI,CAAC,KAAK,GAAG,OAAO;4BAChB,WAAW;4BACX,WAAW;wBACf;wBAEA,kBAAkB;oBACtB;oBAEA,gBAAgB,OAAO;gBAC3B;gBAEA,iBAAiB,UAAU;oBACvB;gBACJ,GAAG;oBAAE,SAAS;oBAAM,SAAS;gBAAK;YACtC;YAEA,IAAI,CAAC,QAAQ,gBAAgB,QAAQ,iBACjC,IAAI,CAAC,QAAQ,gBAAgB,UAAS;YAG1C,OAAO;gBACH,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBAAE,YAAY;gBAAK;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,oBAAoB;QAChB,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,eAAe,IAAI,sBAAsB,eAAe,OAAO,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.breakpoint = this.dataset.mcMax\n ? `(max-width: ${this.dataset.mcMax - 0.02}px)`\n : this.dataset.mcMin\n ? `(min-width: ${this.dataset.mcMin}px)`\n : ''\n\n this.update = this.update.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const wrapper = document.createElement('div')\n wrapper.classList.add('marquee-wrapper')\n\n const inner = document.createElement('div')\n inner.classList.add('marquee-inner')\n inner.style.display = 'inline-block'\n inner.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild)\n }\n\n wrapper.appendChild(inner)\n this.appendChild(wrapper)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n this.MM.add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'\n }\n })\n }\n\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause'\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let currentScroll = 0,\n scrollDirection = 1\n\n const handleScroll = () => {\n let orientation = (window.pageYOffset > currentScroll) ? 1 : -1\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true\n })\n\n scrollDirection = orientation\n }\n\n currentScroll = window.pageYOffset\n }\n\n addEventListener('scroll', () => {\n handleScroll()\n }, { capture: true, passive: true })\n }\n\n this.dataset.mcDirection === 'ltr' ? ltrDirection() :\n this.dataset.mcDirection === 'auto' ? autoDirection() :\n null\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n update() {\n cancelAnimationFrame(this.af)\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n }\n\n connectedCallback() {\n this.templates()\n this.skewed()\n this.cloning()\n this.animation()\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af)\n }\n}\n\ncustomElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,cAAc;QACV,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,QAAQ,OACb,IAAI,CAAC,aAAa,CAAC,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AAO;gBACH,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBACzB,YAAY;gBAChB;YACJ;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n }\n\n debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\n };\n }\n\n templates() {\n const wrapper = document.createElement('div');\n wrapper.classList.add('marquee-wrapper');\n\n const inner = document.createElement('div');\n inner.classList.add('marquee-inner');\n inner.style.display = 'inline-block';\n inner.style.whiteSpace = 'nowrap';\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild);\n }\n\n wrapper.appendChild(inner);\n this.appendChild(wrapper);\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const clone = cloned.cloneNode(true);\n cloned.parentNode.append(clone);\n }\n }\n\n return () => {\n removingClones();\n };\n });\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n }\n\n animation() {\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n },\n }).totalProgress(0.5);\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n this.gsap.set(this.children, {\n clearProps: true,\n });\n };\n });\n }\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning();\n this.animation();\n });\n }\n }\n\n init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -3,7 +3,6 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
3
3
  super();
4
4
  this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
5
5
  this.MM = this.gsap.matchMedia();
6
- this.breakpoint = this.dataset.mcMax ? `(max-width: ${this.dataset.mcMax - 0.02}px)` : this.dataset.mcMin ? `(min-width: ${this.dataset.mcMin}px)` : "";
7
6
  this.update = this.update.bind(this);
8
7
  this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
9
8
  this.resizeObserver.observe(this);
@@ -11,11 +10,16 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
11
10
  static registerGSAP(gsap) {
12
11
  $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
13
12
  }
13
+ breakpoints() {
14
+ this.breakpoint = "";
15
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
16
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
17
+ }
14
18
  debounce(fn, delay) {
15
- let timer;
19
+ this.timer = null;
16
20
  return (...args)=>{
17
- if (timer) clearTimeout(timer);
18
- timer = setTimeout(()=>fn(...args), delay);
21
+ if (this.timer) clearTimeout(this.timer);
22
+ this.timer = setTimeout(()=>fn(...args), delay);
19
23
  };
20
24
  }
21
25
  templates() {
@@ -35,10 +39,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
35
39
  };
36
40
  removingClones();
37
41
  this.MM.add(this.breakpoint, ()=>{
38
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
39
- if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
40
- let cloned = this.firstElementChild;
41
- let clone = cloned.cloneNode(true);
42
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
43
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i += 1){
44
+ const cloned = this.firstElementChild;
45
+ const clone = cloned.cloneNode(true);
42
46
  cloned.parentNode.append(clone);
43
47
  }
44
48
  return ()=>{
@@ -48,8 +52,8 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
48
52
  }
49
53
  skewed() {
50
54
  if (!this.dataset.mcSkew) return;
51
- const abs = Math.abs(parseInt(this.dataset.mcSkew));
52
- const style = this.style;
55
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
56
+ const { style: style } = this;
53
57
  this.MM.add(this.breakpoint, ()=>{
54
58
  style.transformOrigin = "center center";
55
59
  style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
@@ -60,16 +64,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
60
64
  });
61
65
  }
62
66
  animation() {
63
- let timeLine = this.gsap.timeline();
64
- timeLine.kill();
65
- timeLine = null;
66
67
  this.gsap.set(this.children, {
67
68
  clearProps: true
68
69
  });
69
70
  this.MM.add(this.breakpoint, ()=>{
70
- this.gsap.set(this.children, {
71
- "will-change": "transform"
72
- });
73
71
  const tween = this.gsap.to(this.children, {
74
72
  duration: this.dataset.mcDuration || 20,
75
73
  x: "-100%",
@@ -89,9 +87,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
89
87
  });
90
88
  };
91
89
  const autoDirection = ()=>{
92
- let currentScroll = 0, scrollDirection = 1;
90
+ let currentScroll = 0;
91
+ let scrollDirection = 1;
93
92
  const handleScroll = ()=>{
94
- let orientation = window.pageYOffset > currentScroll ? 1 : -1;
93
+ const orientation = window.scrollY > currentScroll ? 1 : -1;
95
94
  if (orientation !== scrollDirection) {
96
95
  this.gsap.to(tween, {
97
96
  timeScale: orientation,
@@ -99,16 +98,15 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
99
98
  });
100
99
  scrollDirection = orientation;
101
100
  }
102
- currentScroll = window.pageYOffset;
101
+ currentScroll = window.scrollY;
103
102
  };
104
- addEventListener("scroll", ()=>{
105
- handleScroll();
106
- }, {
103
+ window.addEventListener("scroll", handleScroll, {
107
104
  capture: true,
108
105
  passive: true
109
106
  });
110
107
  };
111
- this.dataset.mcDirection === "ltr" ? ltrDirection() : this.dataset.mcDirection === "auto" && autoDirection();
108
+ if (this.dataset.mcDirection === "ltr") ltrDirection();
109
+ else if (this.dataset.mcDirection === "auto") autoDirection();
112
110
  return ()=>{
113
111
  this.gsap.set(this.children, {
114
112
  clearProps: true
@@ -123,17 +121,21 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
123
121
  this.animation();
124
122
  });
125
123
  }
126
- connectedCallback() {
124
+ init() {
125
+ this.breakpoints();
127
126
  this.templates();
128
127
  this.skewed();
129
128
  this.cloning();
130
129
  this.animation();
131
130
  }
131
+ connectedCallback() {
132
+ this.init();
133
+ }
132
134
  disconnectedCallback() {
133
135
  cancelAnimationFrame(this.af);
134
136
  }
135
137
  }
136
- customElements.get("marquee-content") || customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
138
+ if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
137
139
 
138
140
 
139
141
  export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
@@ -1 +1 @@
1
- {"mappings":"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,MAAM,gBAAgB;gBAClB,IAAI,gBAAgB,GAChB,kBAAkB;gBAEtB,MAAM,eAAe;oBACjB,IAAI,cAAc,AAAC,OAAO,cAAc,gBAAiB,IAAI;oBAE7D,IAAI,gBAAgB,iBAAiB;wBACjC,IAAI,CAAC,KAAK,GAAG,OAAO;4BAChB,WAAW;4BACX,WAAW;wBACf;wBAEA,kBAAkB;oBACtB;oBAEA,gBAAgB,OAAO;gBAC3B;gBAEA,iBAAiB,UAAU;oBACvB;gBACJ,GAAG;oBAAE,SAAS;oBAAM,SAAS;gBAAK;YACtC;YAEA,IAAI,CAAC,QAAQ,gBAAgB,QAAQ,iBACjC,IAAI,CAAC,QAAQ,gBAAgB,UAAS;YAG1C,OAAO;gBACH,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBAAE,YAAY;gBAAK;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,oBAAoB;QAChB,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,eAAe,IAAI,sBAAsB,eAAe,OAAO,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.breakpoint = this.dataset.mcMax\n ? `(max-width: ${this.dataset.mcMax - 0.02}px)`\n : this.dataset.mcMin\n ? `(min-width: ${this.dataset.mcMin}px)`\n : ''\n\n this.update = this.update.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const wrapper = document.createElement('div')\n wrapper.classList.add('marquee-wrapper')\n\n const inner = document.createElement('div')\n inner.classList.add('marquee-inner')\n inner.style.display = 'inline-block'\n inner.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild)\n }\n\n wrapper.appendChild(inner)\n this.appendChild(wrapper)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n this.MM.add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'\n }\n })\n }\n\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause'\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let currentScroll = 0,\n scrollDirection = 1\n\n const handleScroll = () => {\n let orientation = (window.pageYOffset > currentScroll) ? 1 : -1\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true\n })\n\n scrollDirection = orientation\n }\n\n currentScroll = window.pageYOffset\n }\n\n addEventListener('scroll', () => {\n handleScroll()\n }, { capture: true, passive: true })\n }\n\n this.dataset.mcDirection === 'ltr' ? ltrDirection() :\n this.dataset.mcDirection === 'auto' ? autoDirection() :\n null\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n update() {\n cancelAnimationFrame(this.af)\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n }\n\n connectedCallback() {\n this.templates()\n this.skewed()\n this.cloning()\n this.animation()\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af)\n }\n}\n\ncustomElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,cAAc;QACV,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,QAAQ,OACb,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,QAAQ,K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,CAAC,UAAU;oBACzB,YAAY;gBAChB;YACJ;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n }\n\n debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\n };\n }\n\n templates() {\n const wrapper = document.createElement('div');\n wrapper.classList.add('marquee-wrapper');\n\n const inner = document.createElement('div');\n inner.classList.add('marquee-inner');\n inner.style.display = 'inline-block';\n inner.style.whiteSpace = 'nowrap';\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild);\n }\n\n wrapper.appendChild(inner);\n this.appendChild(wrapper);\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const clone = cloned.cloneNode(true);\n cloned.parentNode.append(clone);\n }\n }\n\n return () => {\n removingClones();\n };\n });\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n }\n\n animation() {\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n const tween = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n },\n }).totalProgress(0.5);\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n this.gsap.set(this.children, {\n clearProps: true,\n });\n };\n });\n }\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning();\n this.animation();\n });\n }\n }\n\n init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "2.1.2",
4
- "description": "Infinite marquee animation with GSAP",
3
+ "version": "2.3.0",
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",
7
7
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "clean": "rm -rf dist .parcel-cache"
21
21
  },
22
22
  "devDependencies": {
23
- "parcel": "~2.9.2"
23
+ "parcel": "~2.9.3"
24
24
  },
25
25
  "keywords": [
26
26
  "marquee",
package/src/index.js CHANGED
@@ -1,104 +1,101 @@
1
1
  export default class MarqueeContent extends HTMLElement {
2
2
  constructor() {
3
- super()
4
-
5
- this.gsap = MarqueeContent.gsap || window.gsap
6
- this.MM = this.gsap.matchMedia()
7
- this.breakpoint = this.dataset.mcMax
8
- ? `(max-width: ${this.dataset.mcMax - 0.02}px)`
9
- : this.dataset.mcMin
10
- ? `(min-width: ${this.dataset.mcMin}px)`
11
- : ''
12
-
13
- this.update = this.update.bind(this)
14
- this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150))
15
- this.resizeObserver.observe(this)
3
+ super();
4
+
5
+ this.gsap = MarqueeContent.gsap || window.gsap;
6
+ this.MM = this.gsap.matchMedia();
7
+ this.update = this.update.bind(this);
8
+ this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
9
+ this.resizeObserver.observe(this);
16
10
  }
17
11
 
18
12
  static registerGSAP(gsap) {
19
- MarqueeContent.gsap = gsap
13
+ MarqueeContent.gsap = gsap;
14
+ }
15
+
16
+ breakpoints() {
17
+ this.breakpoint = '';
18
+
19
+ if (this.dataset.mcMax) {
20
+ this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
21
+ } else if (this.dataset.mcMin) {
22
+ this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
23
+ }
20
24
  }
21
25
 
22
26
  debounce(fn, delay) {
23
- let timer
27
+ this.timer = null;
24
28
 
25
29
  return (...args) => {
26
- if (timer) clearTimeout(timer)
27
- timer = setTimeout(() => fn(...args), delay)
28
- }
30
+ if (this.timer) clearTimeout(this.timer);
31
+ this.timer = setTimeout(() => fn(...args), delay);
32
+ };
29
33
  }
30
34
 
31
35
  templates() {
32
- const wrapper = document.createElement('div')
33
- wrapper.classList.add('marquee-wrapper')
36
+ const wrapper = document.createElement('div');
37
+ wrapper.classList.add('marquee-wrapper');
34
38
 
35
- const inner = document.createElement('div')
36
- inner.classList.add('marquee-inner')
37
- inner.style.display = 'inline-block'
38
- inner.style.whiteSpace = 'nowrap'
39
+ const inner = document.createElement('div');
40
+ inner.classList.add('marquee-inner');
41
+ inner.style.display = 'inline-block';
42
+ inner.style.whiteSpace = 'nowrap';
39
43
 
40
44
  while (this.firstChild) {
41
- inner.appendChild(this.firstChild)
45
+ inner.appendChild(this.firstChild);
42
46
  }
43
47
 
44
- wrapper.appendChild(inner)
45
- this.appendChild(wrapper)
48
+ wrapper.appendChild(inner);
49
+ this.appendChild(wrapper);
46
50
  }
47
51
 
48
52
  cloning() {
49
53
  const removingClones = () => {
50
54
  while (this.childElementCount > 1) {
51
- this.removeChild(this.lastChild)
55
+ this.removeChild(this.lastChild);
52
56
  }
53
- }
57
+ };
54
58
 
55
- removingClones()
59
+ removingClones();
56
60
 
57
61
  this.MM.add(this.breakpoint, () => {
58
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)
62
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
59
63
 
60
64
  if (this.childElementCount < requiredQuantity) {
61
- for (let i = 1; i < requiredQuantity; i++) {
62
- let cloned = this.firstElementChild
63
- let clone = cloned.cloneNode(true)
64
- cloned.parentNode.append(clone)
65
+ for (let i = 1; i < requiredQuantity; i += 1) {
66
+ const cloned = this.firstElementChild;
67
+ const clone = cloned.cloneNode(true);
68
+ cloned.parentNode.append(clone);
65
69
  }
66
70
  }
67
71
 
68
72
  return () => {
69
- removingClones()
70
- }
71
- })
73
+ removingClones();
74
+ };
75
+ });
72
76
  }
73
77
 
74
78
  skewed() {
75
- if (!this.dataset.mcSkew) return
79
+ if (!this.dataset.mcSkew) return;
76
80
 
77
- const abs = Math.abs(parseInt(this.dataset.mcSkew))
78
- const style = this.style
81
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
82
+ const { style } = this;
79
83
 
80
84
  this.MM.add(this.breakpoint, () => {
81
- style.transformOrigin = 'center center'
82
- style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`
83
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
85
+ style.transformOrigin = 'center center';
86
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
87
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
84
88
 
85
89
  return () => {
86
- style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'
87
- }
88
- })
90
+ style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
91
+ };
92
+ });
89
93
  }
90
94
 
91
95
  animation() {
92
- let timeLine = this.gsap.timeline()
93
-
94
- timeLine.kill()
95
- timeLine = null
96
-
97
- this.gsap.set(this.children, { clearProps: true })
96
+ this.gsap.set(this.children, { clearProps: true });
98
97
 
99
98
  this.MM.add(this.breakpoint, () => {
100
- this.gsap.set(this.children, { 'will-change': 'transform' })
101
-
102
99
  const tween = this.gsap.to(this.children, {
103
100
  duration: this.dataset.mcDuration || 20,
104
101
  x: '-100%',
@@ -108,72 +105,81 @@ export default class MarqueeContent extends HTMLElement {
108
105
  trigger: this,
109
106
  start: '-=50% bottom',
110
107
  end: 'bottom top',
111
- toggleActions: 'resume pause resume pause'
108
+ toggleActions: 'resume pause resume pause',
112
109
  },
113
- }).totalProgress(0.5)
110
+ }).totalProgress(0.5);
114
111
 
115
112
  const ltrDirection = () => {
116
113
  this.gsap.to(tween, {
117
114
  timeScale: -1,
118
- overwrite: true
119
- })
120
- }
115
+ overwrite: true,
116
+ });
117
+ };
121
118
 
122
119
  const autoDirection = () => {
123
- let currentScroll = 0,
124
- scrollDirection = 1
120
+ let currentScroll = 0;
121
+ let scrollDirection = 1;
125
122
 
126
123
  const handleScroll = () => {
127
- let orientation = (window.pageYOffset > currentScroll) ? 1 : -1
124
+ const orientation = (window.scrollY > currentScroll) ? 1 : -1;
128
125
 
129
126
  if (orientation !== scrollDirection) {
130
127
  this.gsap.to(tween, {
131
128
  timeScale: orientation,
132
- overwrite: true
133
- })
129
+ overwrite: true,
130
+ });
134
131
 
135
- scrollDirection = orientation
132
+ scrollDirection = orientation;
136
133
  }
137
134
 
138
- currentScroll = window.pageYOffset
139
- }
135
+ currentScroll = window.scrollY;
136
+ };
140
137
 
141
- addEventListener('scroll', () => {
142
- handleScroll()
143
- }, { capture: true, passive: true })
144
- }
138
+ window.addEventListener('scroll', handleScroll, { capture: true, passive: true });
139
+ };
145
140
 
146
- this.dataset.mcDirection === 'ltr' ? ltrDirection() :
147
- this.dataset.mcDirection === 'auto' ? autoDirection() :
148
- null
141
+ if (this.dataset.mcDirection === 'ltr') {
142
+ ltrDirection();
143
+ } else if (this.dataset.mcDirection === 'auto') {
144
+ autoDirection();
145
+ }
149
146
 
150
147
  return () => {
151
- this.gsap.set(this.children, { clearProps: true })
152
- }
153
- })
148
+ this.gsap.set(this.children, {
149
+ clearProps: true,
150
+ });
151
+ };
152
+ });
154
153
  }
155
154
 
156
155
  update() {
157
- cancelAnimationFrame(this.af)
156
+ cancelAnimationFrame(this.af);
158
157
 
159
158
  if (this.firstElementChild) {
160
159
  this.af = requestAnimationFrame(() => {
161
- this.cloning()
162
- this.animation()
163
- })
160
+ this.cloning();
161
+ this.animation();
162
+ });
164
163
  }
165
164
  }
166
165
 
166
+ init() {
167
+ this.breakpoints();
168
+ this.templates();
169
+ this.skewed();
170
+ this.cloning();
171
+ this.animation();
172
+ }
173
+
167
174
  connectedCallback() {
168
- this.templates()
169
- this.skewed()
170
- this.cloning()
171
- this.animation()
175
+ this.init();
172
176
  }
173
177
 
174
178
  disconnectedCallback() {
175
- cancelAnimationFrame(this.af)
179
+ cancelAnimationFrame(this.af);
176
180
  }
177
181
  }
178
182
 
179
- customElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)
183
+ if (!customElements.get('marquee-content')) {
184
+ customElements.define('marquee-content', MarqueeContent);
185
+ }