marquee-content 1.9.9 → 2.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/dist/index.js CHANGED
@@ -9,16 +9,14 @@ $parcel$defineInteropFlag(module.exports);
9
9
 
10
10
  $parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
11
11
  class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
12
- constructor(query){
12
+ constructor(){
13
13
  super();
14
14
  this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
15
- this.MM = this.gsap.matchMedia(query);
16
- this.dataSkew = this.dataset.mcSkew;
17
- this.dataDuration = this.dataset.mcDuration || 20;
18
- this.dataDirection = this.dataset.mcDirection;
19
- this.dataMaxWidth = this.dataset.mcMax;
20
- this.dataMinWidth = this.dataset.mcMin;
21
- this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
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
+ this.onResize = this.onResize.bind(this);
18
+ this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
19
+ this.resizeObserver.observe(this);
22
20
  }
23
21
  static registerGSAP(gsap) {
24
22
  $4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
@@ -31,11 +29,15 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
31
29
  };
32
30
  }
33
31
  templates() {
34
- const div = document.createElement("div");
35
- div.style.display = "inline-block";
36
- div.style.whiteSpace = "nowrap";
37
- while(this.firstChild)div.appendChild(this.firstChild);
38
- this.appendChild(div);
32
+ const wrapper = document.createElement("div");
33
+ wrapper.classList.add("marquee-wrapper");
34
+ const inner = document.createElement("div");
35
+ inner.classList.add("marquee-inner");
36
+ inner.style.display = "inline-block";
37
+ inner.style.whiteSpace = "nowrap";
38
+ while(this.firstChild)inner.appendChild(this.firstChild);
39
+ wrapper.appendChild(inner);
40
+ this.appendChild(wrapper);
39
41
  }
40
42
  cloning() {
41
43
  const removingClones = ()=>{
@@ -55,12 +57,12 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
55
57
  });
56
58
  }
57
59
  skewed() {
58
- if (!this.dataSkew) return;
59
- const abs = Math.abs(parseInt(this.dataSkew));
60
+ if (!this.dataset.mcSkew) return;
61
+ const abs = Math.abs(parseInt(this.dataset.mcSkew));
60
62
  const style = this.style;
61
63
  this.MM.add(this.breakpoint, ()=>{
62
64
  style.transformOrigin = "center center";
63
- style.transform = `skew(0deg, ${this.dataSkew}deg)`;
65
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
64
66
  style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
65
67
  return ()=>{
66
68
  style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
@@ -79,7 +81,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
79
81
  "will-change": "transform"
80
82
  });
81
83
  const tween = this.gsap.to(this.children, {
82
- duration: this.dataDuration,
84
+ duration: this.dataset.mcDuration || 20,
83
85
  x: "-100%",
84
86
  ease: "none",
85
87
  repeat: -1,
@@ -97,28 +99,27 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
97
99
  });
98
100
  };
99
101
  const autoDirection = ()=>{
100
- let previousScrollPosition = 0;
101
- const isScrollingDown = ()=>{
102
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
103
- let direction = false;
104
- if (scrollPosition > previousScrollPosition) direction = true;
105
- else if (scrollPosition < previousScrollPosition) direction = false;
106
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
107
- return direction;
102
+ let currentScroll = 0, scrollDirection = 1;
103
+ const handleScroll = ()=>{
104
+ let orientation = window.pageYOffset > currentScroll ? 1 : -1;
105
+ if (orientation !== scrollDirection) {
106
+ this.gsap.to(tween, {
107
+ timeScale: orientation,
108
+ overwrite: true
109
+ });
110
+ scrollDirection = orientation;
111
+ }
112
+ currentScroll = window.pageYOffset;
108
113
  };
109
- addEventListener("scroll", this.debounce(()=>{
110
- const scrollDirection = isScrollingDown();
111
- this.gsap.to(tween, {
112
- timeScale: scrollDirection ? 1 : -1,
113
- overwrite: true
114
- });
115
- }, 50), {
114
+ addEventListener("scroll", ()=>{
115
+ handleScroll();
116
+ }, {
116
117
  capture: true,
117
118
  passive: true
118
119
  });
119
120
  };
120
- if (this.dataDirection === "ltr") ltrDirection();
121
- else if (this.dataDirection === "auto") autoDirection();
121
+ if (this.dataset.mcDirection === "ltr") ltrDirection();
122
+ else if (this.dataset.mcDirection === "auto") autoDirection();
122
123
  return ()=>{
123
124
  this.gsap.set(this.children, {
124
125
  clearProps: true
@@ -128,29 +129,22 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
128
129
  }
129
130
  onResize() {
130
131
  cancelAnimationFrame(this.af);
131
- this.af = requestAnimationFrame(()=>{
132
+ if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
132
133
  this.cloning();
133
134
  this.animation();
134
135
  });
135
136
  }
136
- onUpdate() {
137
+ connectedCallback() {
137
138
  this.templates();
138
139
  this.cloning();
139
140
  this.skewed();
140
141
  this.animation();
141
- this.onResize = this.onResize.bind(this);
142
- this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
143
- this.resizeObserver.observe(this);
144
- }
145
- connectedCallback() {
146
- this.onUpdate();
147
142
  }
148
143
  disconnectedCallback() {
149
- this.MM.remove();
150
- document.fonts.removeEventListener("loadingdone", this.onUpdate);
144
+ cancelAnimationFrame(this.af);
151
145
  }
152
146
  }
153
- customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
147
+ customElements.get("marquee-content") || customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
154
148
 
155
149
 
156
150
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,GAC7B,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,GAAG,KAAK,GAAG,CAAC,GAC5C,IAAI,CAAC,YAAY,GACb,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GACrC,EAAE;IAChB;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,IAAI,GAAG;IAC1B;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI;QAEJ,OAAO,CAAC,GAAG,OAAS;YAChB,IAAI,OAAO,aAAa;YACxB,QAAQ,WAAW,IAAM,MAAM,OAAO;QAC1C;IACJ;IAEA,YAAY;QACR,MAAM,MAAM,SAAS,aAAa,CAAC;QAEnC,IAAI,KAAK,CAAC,OAAO,GAAG;QACpB,IAAI,KAAK,CAAC,UAAU,GAAG;QAEvB,MAAO,IAAI,CAAC,UAAU,CAClB,IA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G,IAAI,IAAI,CAAC,aAAa,KAAK,QAC9B;YAGJ,OAAO,IAAM;gBACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAAE,YAAY,IAAI;gBAAC;YACpD;QACJ;IACJ;IAEA,WAAW;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IACJ;IAEA,WAAW;QACP,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\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 div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\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.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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.dataDuration,\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 previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,GAC9B,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,GAC7C,IAAI,CAAC,OAAO,CAAC,KAAK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C,SAAS;IAClB;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC,EAAE;IAChC;AACJ;AAEA,eAAe,GAAG,CAAC,sBAAsB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.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.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.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 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, { clearProps: true })\n }\n })\n }\n\n onResize() {\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.cloning()\n this.skewed()\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,14 +1,12 @@
1
1
  class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
2
- constructor(query){
2
+ constructor(){
3
3
  super();
4
4
  this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
5
- this.MM = this.gsap.matchMedia(query);
6
- this.dataSkew = this.dataset.mcSkew;
7
- this.dataDuration = this.dataset.mcDuration || 20;
8
- this.dataDirection = this.dataset.mcDirection;
9
- this.dataMaxWidth = this.dataset.mcMax;
10
- this.dataMinWidth = this.dataset.mcMin;
11
- this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
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
+ this.onResize = this.onResize.bind(this);
8
+ this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
9
+ this.resizeObserver.observe(this);
12
10
  }
13
11
  static registerGSAP(gsap) {
14
12
  $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
@@ -21,11 +19,15 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
21
19
  };
22
20
  }
23
21
  templates() {
24
- const div = document.createElement("div");
25
- div.style.display = "inline-block";
26
- div.style.whiteSpace = "nowrap";
27
- while(this.firstChild)div.appendChild(this.firstChild);
28
- this.appendChild(div);
22
+ const wrapper = document.createElement("div");
23
+ wrapper.classList.add("marquee-wrapper");
24
+ const inner = document.createElement("div");
25
+ inner.classList.add("marquee-inner");
26
+ inner.style.display = "inline-block";
27
+ inner.style.whiteSpace = "nowrap";
28
+ while(this.firstChild)inner.appendChild(this.firstChild);
29
+ wrapper.appendChild(inner);
30
+ this.appendChild(wrapper);
29
31
  }
30
32
  cloning() {
31
33
  const removingClones = ()=>{
@@ -45,12 +47,12 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
45
47
  });
46
48
  }
47
49
  skewed() {
48
- if (!this.dataSkew) return;
49
- const abs = Math.abs(parseInt(this.dataSkew));
50
+ if (!this.dataset.mcSkew) return;
51
+ const abs = Math.abs(parseInt(this.dataset.mcSkew));
50
52
  const style = this.style;
51
53
  this.MM.add(this.breakpoint, ()=>{
52
54
  style.transformOrigin = "center center";
53
- style.transform = `skew(0deg, ${this.dataSkew}deg)`;
55
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
54
56
  style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
55
57
  return ()=>{
56
58
  style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
@@ -69,7 +71,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
69
71
  "will-change": "transform"
70
72
  });
71
73
  const tween = this.gsap.to(this.children, {
72
- duration: this.dataDuration,
74
+ duration: this.dataset.mcDuration || 20,
73
75
  x: "-100%",
74
76
  ease: "none",
75
77
  repeat: -1,
@@ -87,28 +89,27 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
87
89
  });
88
90
  };
89
91
  const autoDirection = ()=>{
90
- let previousScrollPosition = 0;
91
- const isScrollingDown = ()=>{
92
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
93
- let direction = false;
94
- if (scrollPosition > previousScrollPosition) direction = true;
95
- else if (scrollPosition < previousScrollPosition) direction = false;
96
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
97
- return direction;
92
+ let currentScroll = 0, scrollDirection = 1;
93
+ const handleScroll = ()=>{
94
+ let orientation = window.pageYOffset > currentScroll ? 1 : -1;
95
+ if (orientation !== scrollDirection) {
96
+ this.gsap.to(tween, {
97
+ timeScale: orientation,
98
+ overwrite: true
99
+ });
100
+ scrollDirection = orientation;
101
+ }
102
+ currentScroll = window.pageYOffset;
98
103
  };
99
- addEventListener("scroll", this.debounce(()=>{
100
- const scrollDirection = isScrollingDown();
101
- this.gsap.to(tween, {
102
- timeScale: scrollDirection ? 1 : -1,
103
- overwrite: true
104
- });
105
- }, 50), {
104
+ addEventListener("scroll", ()=>{
105
+ handleScroll();
106
+ }, {
106
107
  capture: true,
107
108
  passive: true
108
109
  });
109
110
  };
110
- if (this.dataDirection === "ltr") ltrDirection();
111
- else if (this.dataDirection === "auto") autoDirection();
111
+ if (this.dataset.mcDirection === "ltr") ltrDirection();
112
+ else if (this.dataset.mcDirection === "auto") autoDirection();
112
113
  return ()=>{
113
114
  this.gsap.set(this.children, {
114
115
  clearProps: true
@@ -118,29 +119,22 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
118
119
  }
119
120
  onResize() {
120
121
  cancelAnimationFrame(this.af);
121
- this.af = requestAnimationFrame(()=>{
122
+ if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
122
123
  this.cloning();
123
124
  this.animation();
124
125
  });
125
126
  }
126
- onUpdate() {
127
+ connectedCallback() {
127
128
  this.templates();
128
129
  this.cloning();
129
130
  this.skewed();
130
131
  this.animation();
131
- this.onResize = this.onResize.bind(this);
132
- this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
133
- this.resizeObserver.observe(this);
134
- }
135
- connectedCallback() {
136
- this.onUpdate();
137
132
  }
138
133
  disconnectedCallback() {
139
- this.MM.remove();
140
- document.fonts.removeEventListener("loadingdone", this.onUpdate);
134
+ cancelAnimationFrame(this.af);
141
135
  }
142
136
  }
143
- customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
137
+ customElements.get("marquee-content") || customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
144
138
 
145
139
 
146
140
  export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
@@ -1 +1 @@
1
- {"mappings":"AAAe,uDAA6B;IACxC,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CA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E;QAE5B,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IACJ;IAEA,WAAW;QACP,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\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 div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\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.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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.dataDuration,\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 previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,GAC9B,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,GAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,GAClB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GACtC,EAAE;QAER,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,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AAC,OAAO;oBAChB,WAAW;oBACX,WAAW,IAAI;gBACnB;YACJ;YAEA,MAAM,gBAAgB,IAAM;gBACxB,IAAI,gBAAgB,GAChB,kBAAkB;gBAEtB,MAAM,eAAe,IAAM;oBACvB,IAAI,cAAc,AAAC,OAAO,WAAW,GAAG,gBAAiB,IAAI,EAAE;oBAE/D,IAAI,gBAAgB,iBAAiB;wBACjC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO;4BAChB,WAAW;4BACX,WAAW,IAAI;wBACnB;wBAEA,kBAAkB;oBACtB,CAAC;oBAED,gBAAgB,OAAO,WAAW;gBACtC;gBAEA,iBAAiB,UAAU,IAAM;oBAC7B;gBACJ,GAAG;oBAAE,SAAS,IAAI;oBAAE,SAAS,IAAI;gBAAC;YACtC;YAEA,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,OAC7B;iBACG,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,QACpC;YAGJ,OAAO,IAAM;gBACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAAE,YAAY,IAAI;gBAAC;YACpD;QACJ;IACJ;IAEA,WAAW;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IAER;IAEA,oBAAoB;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;IAClB;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC,EAAE;IAChC;AACJ;AAEA,eAAe,GAAG,CAAC,sBAAsB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia()\n this.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.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.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 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, { clearProps: true })\n }\n })\n }\n\n onResize() {\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.cloning()\n this.skewed()\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "1.9.9",
3
+ "version": "2.0.0",
4
4
  "description": "Infinite marquee animation with GSAP",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
package/src/index.js CHANGED
@@ -1,19 +1,18 @@
1
1
  export default class MarqueeContent extends HTMLElement {
2
- constructor(query) {
2
+ constructor() {
3
3
  super()
4
4
 
5
5
  this.gsap = MarqueeContent.gsap || window.gsap
6
- this.MM = this.gsap.matchMedia(query)
7
- this.dataSkew = this.dataset.mcSkew
8
- this.dataDuration = this.dataset.mcDuration || 20
9
- this.dataDirection = this.dataset.mcDirection
10
- this.dataMaxWidth = this.dataset.mcMax
11
- this.dataMinWidth = this.dataset.mcMin
12
- this.breakpoint = this.dataMaxWidth
13
- ? `(max-width: ${this.dataMaxWidth - 0.02}px)`
14
- : this.dataMinWidth
15
- ? `(min-width: ${this.dataMinWidth}px)`
16
- : ''
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.onResize = this.onResize.bind(this)
14
+ this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))
15
+ this.resizeObserver.observe(this)
17
16
  }
18
17
 
19
18
  static registerGSAP(gsap) {
@@ -30,16 +29,20 @@ export default class MarqueeContent extends HTMLElement {
30
29
  }
31
30
 
32
31
  templates() {
33
- const div = document.createElement('div')
32
+ const wrapper = document.createElement('div')
33
+ wrapper.classList.add('marquee-wrapper')
34
34
 
35
- div.style.display = 'inline-block'
36
- div.style.whiteSpace = 'nowrap'
35
+ const inner = document.createElement('div')
36
+ inner.classList.add('marquee-inner')
37
+ inner.style.display = 'inline-block'
38
+ inner.style.whiteSpace = 'nowrap'
37
39
 
38
40
  while (this.firstChild) {
39
- div.appendChild(this.firstChild)
41
+ inner.appendChild(this.firstChild)
40
42
  }
41
43
 
42
- this.appendChild(div)
44
+ wrapper.appendChild(inner)
45
+ this.appendChild(wrapper)
43
46
  }
44
47
 
45
48
  cloning() {
@@ -69,14 +72,14 @@ export default class MarqueeContent extends HTMLElement {
69
72
  }
70
73
 
71
74
  skewed() {
72
- if (!this.dataSkew) return
75
+ if (!this.dataset.mcSkew) return
73
76
 
74
- const abs = Math.abs(parseInt(this.dataSkew))
77
+ const abs = Math.abs(parseInt(this.dataset.mcSkew))
75
78
  const style = this.style
76
79
 
77
80
  this.MM.add(this.breakpoint, () => {
78
81
  style.transformOrigin = 'center center'
79
- style.transform = `skew(0deg, ${this.dataSkew}deg)`
82
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`
80
83
  style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
81
84
 
82
85
  return () => {
@@ -97,7 +100,7 @@ export default class MarqueeContent extends HTMLElement {
97
100
  this.gsap.set(this.children, { 'will-change': 'transform' })
98
101
 
99
102
  const tween = this.gsap.to(this.children, {
100
- duration: this.dataDuration,
103
+ duration: this.dataset.mcDuration || 20,
101
104
  x: '-100%',
102
105
  ease: 'none',
103
106
  repeat: -1,
@@ -105,7 +108,7 @@ export default class MarqueeContent extends HTMLElement {
105
108
  trigger: this,
106
109
  start: '-=50% bottom',
107
110
  end: 'bottom top',
108
- toggleActions: 'resume pause resume pause',
111
+ toggleActions: 'resume pause resume pause'
109
112
  },
110
113
  }).totalProgress(0.5)
111
114
 
@@ -117,39 +120,32 @@ export default class MarqueeContent extends HTMLElement {
117
120
  }
118
121
 
119
122
  const autoDirection = () => {
120
- let previousScrollPosition = 0
123
+ let currentScroll = 0,
124
+ scrollDirection = 1
121
125
 
122
- const isScrollingDown = () => {
123
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop
126
+ const handleScroll = () => {
127
+ let orientation = (window.pageYOffset > currentScroll) ? 1 : -1
124
128
 
125
- let direction = false
129
+ if (orientation !== scrollDirection) {
130
+ this.gsap.to(tween, {
131
+ timeScale: orientation,
132
+ overwrite: true
133
+ })
126
134
 
127
- if (scrollPosition > previousScrollPosition) {
128
- direction = true
129
- } else if (scrollPosition < previousScrollPosition) {
130
- direction = false
135
+ scrollDirection = orientation
131
136
  }
132
137
 
133
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition
134
-
135
- return direction
138
+ currentScroll = window.pageYOffset
136
139
  }
137
140
 
138
- addEventListener('scroll', this.debounce(() => {
139
- const scrollDirection = isScrollingDown()
140
-
141
- this.gsap.to(tween, {
142
- timeScale: scrollDirection ? 1 : -1,
143
- overwrite: true,
144
- })
145
- }, 50), {
146
- capture: true, passive: true
147
- })
141
+ addEventListener('scroll', () => {
142
+ handleScroll()
143
+ }, { capture: true, passive: true })
148
144
  }
149
145
 
150
- if (this.dataDirection === 'ltr') {
146
+ if (this.dataset.mcDirection === 'ltr') {
151
147
  ltrDirection()
152
- } else if (this.dataDirection === 'auto') {
148
+ } else if (this.dataset.mcDirection === 'auto') {
153
149
  autoDirection()
154
150
  }
155
151
 
@@ -162,32 +158,24 @@ export default class MarqueeContent extends HTMLElement {
162
158
  onResize() {
163
159
  cancelAnimationFrame(this.af)
164
160
 
165
- this.af = requestAnimationFrame(() => {
166
- this.cloning()
167
- this.animation()
168
- })
161
+ if (this.firstElementChild) {
162
+ this.af = requestAnimationFrame(() => {
163
+ this.cloning()
164
+ this.animation()
165
+ })
166
+ }
169
167
  }
170
168
 
171
- onUpdate() {
169
+ connectedCallback() {
172
170
  this.templates()
173
171
  this.cloning()
174
172
  this.skewed()
175
173
  this.animation()
176
-
177
- this.onResize = this.onResize.bind(this)
178
- this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))
179
- this.resizeObserver.observe(this)
180
- }
181
-
182
- connectedCallback() {
183
- this.onUpdate()
184
174
  }
185
175
 
186
176
  disconnectedCallback() {
187
- this.MM.remove()
188
-
189
- document.fonts.removeEventListener('loadingdone', this.onUpdate)
177
+ cancelAnimationFrame(this.af)
190
178
  }
191
179
  }
192
180
 
193
- customElements.define('marquee-content', MarqueeContent)
181
+ customElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)