marquee-content 1.1.1 → 1.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
@@ -2,12 +2,14 @@
2
2
  <br>
3
3
 
4
4
  <h1>marquee-content</h1>
5
+ <p><sup>Infinite marquee animation with <a href="https://www.npmjs.com/package/gsap">GSAP</a></sup></p>
6
+
5
7
 
6
8
  [![npm](https://img.shields.io/npm/v/marquee-content.svg?colorB=brightgreen)](https://www.npmjs.com/package/marquee-content)
7
9
  [![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
10
  [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.org/package/marquee-content)
9
11
 
10
- <sup><a href="https://bundlephobia.com/package/marquee-content">1Kb gzipped</a></sup>
12
+ <p><sup><a href="https://bundlephobia.com/package/marquee-content">1Kb gzipped</a></sup></p>
11
13
 
12
14
  <h3><a href="https://ux-ui-pro.github.io/marquee-content/dist/">Demo</a></h3>
13
15
 
@@ -27,19 +29,14 @@ $ npm i marquee-content
27
29
 
28
30
  ### Import
29
31
  ```javascript
30
- import { gsap } from 'gsap'
31
- import { ScrollTrigger } from 'gsap/ScrollTrigger'
32
-
33
32
  import { MarqueeContent } from 'marquee-content'
34
-
35
- gsap.registerPlugin(ScrollTrigger)
36
33
  ```
37
34
  <br>
38
35
 
39
36
  ### Usage
40
37
  ```HTML
41
- <marquee-content
42
- data-mc-duration="60"
38
+ <div class="marquee-content"
39
+ data-mc-duration="20"
43
40
  role="marquee">
44
41
  <ul>
45
42
  <li>Primary</li>
@@ -47,7 +44,7 @@ gsap.registerPlugin(ScrollTrigger)
47
44
  <li>Tertiary</li>
48
45
  <li>Quaternary</li>
49
46
  </ul>
50
- </marquee-content>
47
+ </div>
51
48
  ```
52
49
  <br>
53
50
 
package/dist/index.html CHANGED
@@ -11,7 +11,7 @@
11
11
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12
12
  <link href="https://fonts.googleapis.com/css2?family=Alkatra:wght@700&family=Anton&family=Lobster&family=PT+Sans+Narrow:wght@700&family=Prompt:wght@500&display=swap" rel="stylesheet">
13
13
  <style type="text/css">
14
- 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: 150px 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: 80px auto 30px;padding: 0 20px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
14
+ 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: 150px 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: 80px auto 30px;padding: 0 20px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
15
15
  </style>
16
16
  </head>
17
17
  <body>
@@ -20,7 +20,7 @@
20
20
  <p>The basic version, with scrolling content from right to left</p>
21
21
  </section>
22
22
  <section class="example-1">
23
- <marquee-content
23
+ <div class="marquee-content"
24
24
  data-mc-duration="60"
25
25
  role="marquee">
26
26
  <ul class="font alkatra">
@@ -33,10 +33,10 @@
33
33
  <li>Vomero</li>
34
34
  <li>Pegasus</li>
35
35
  </ul>
36
- </marquee-content>
36
+ </div>
37
37
  </section>
38
38
  <section class="example-7">
39
- <marquee-content
39
+ <div class="marquee-content"
40
40
  data-mc-duration="20"
41
41
  role="marquee">
42
42
  <ul>
@@ -45,14 +45,14 @@
45
45
  <li><img src="//fastly.picsum.photos/id/235/180/100.jpg?hmac=5KlYbDb93R7me0GThn6FFoK_OZ8ziPn-fb98FHIMb5c" alt></li>
46
46
  <li><img src="//fastly.picsum.photos/id/1050/180/100.jpg?hmac=f9i0nGYKBetkohJors44GETXmUhSbLcXMUlSvMCluJY" alt></li>
47
47
  </ul>
48
- </marquee-content>
48
+ </div>
49
49
  </section>
50
50
  <section class="data-code">
51
51
  <strong>data-mc-duration=&quot;60&quot; data-mc-direction=&quot;ltr&quot;</strong>
52
52
  <p><code>data-mc-direction="ltr"</code> &mdash; changes the scroll direction from left to right</p>
53
53
  </section>
54
54
  <section class="example-2">
55
- <marquee-content
55
+ <div class="marquee-content"
56
56
  data-mc-duration="60"
57
57
  data-mc-direction="ltr"
58
58
  role="marquee">
@@ -67,14 +67,14 @@
67
67
  <li><span class="font anton">Vomero</span></li>
68
68
  <li><span class="font pt">Pegasus</span></li>
69
69
  </ul>
70
- </marquee-content>
70
+ </div>
71
71
  </section>
72
72
  <section class="data-code">
73
73
  <strong>data-mc-duration=&quot;60&quot; data-mc-direction=&quot;auto&quot;</strong>
74
74
  <p><code>data-mc-direction="auto"</code> &mdash; automatically changes the scrolling direction of the component when scrolling the page</p>
75
75
  </section>
76
76
  <section class="example-3">
77
- <marquee-content
77
+ <div class="marquee-content"
78
78
  data-mc-duration="60"
79
79
  data-mc-direction="auto"
80
80
  role="marquee">
@@ -89,14 +89,14 @@
89
89
  <li>Vomero</li>
90
90
  <li>Pegasus</li>
91
91
  </ul>
92
- </marquee-content>
92
+ </div>
93
93
  </section>
94
94
  <section class="data-code">
95
95
  <strong>data-mc-duration=&quot;60&quot; data-mc-skew=&quot;-4&quot;</strong>
96
96
  <p><code>data-mc-skew="-4"</code> &mdash; transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value)</p>
97
97
  </section>
98
98
  <section class="example-4">
99
- <marquee-content
99
+ <div class="marquee-content"
100
100
  data-mc-duration="60"
101
101
  data-mc-skew="-4"
102
102
  role="marquee">
@@ -111,35 +111,35 @@
111
111
  <li>Vomero</li>
112
112
  <li>Pegasus</li>
113
113
  </ul>
114
- </marquee-content>
114
+ </div>
115
115
  </section>
116
116
  <section class="data-code">
117
117
  <strong>data-mc-duration=&quot;5&quot; data-mc-min=&quot;992&quot;</strong>
118
118
  <p><code>data-mc-min="992"</code> &mdash; sets the minimum screen 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)</p>
119
119
  </section>
120
120
  <section class="example-5">
121
- <marquee-content
121
+ <div class="marquee-content"
122
122
  data-mc-duration="5"
123
123
  data-mc-min="992"
124
124
  role="marquee">
125
125
  <ul class="font pt">
126
126
  <li>Jordan</li>
127
127
  </ul>
128
- </marquee-content>
128
+ </div>
129
129
  </section>
130
130
  <section class="data-code">
131
131
  <strong>data-mc-duration=&quot;5&quot; data-mc-max=&quot;992&quot;</strong>
132
132
  <p><code>data-mc-max="992"</code> &mdash; sets the maximum screen 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)</p>
133
133
  </section>
134
134
  <section class="example-6">
135
- <marquee-content
135
+ <div class="marquee-content"
136
136
  data-mc-duration="5"
137
137
  data-mc-max="992"
138
138
  role="marquee">
139
139
  <ul class="font pt">
140
140
  <li>Presto</li>
141
141
  </ul>
142
- </marquee-content>
142
+ </div>
143
143
  </section>
144
144
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/gsap.min.js"></script>
145
145
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/ScrollTrigger.min.js"></script>
@@ -1 +1 @@
1
- (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.dur=this.dataset.mcDuration||20,this.skew=this.dataset.mcSkew,this.max=this.dataset.mcMax,this.min=this.dataset.mcMin,this.dir=this.dataset.mcDirection,this.breakpoints(),this.cloning(),this.skewed(),this.marquee(),this.scrollReverse(),this.debounce(),this.resizing()}breakpoints(){this.max||this.min?(this.max&&(this.breakpoint=`(max-width: ${this.max-.02}px)`),this.min&&(this.breakpoint=`(min-width: ${this.min}px)`)):this.breakpoint=""}cloning(){const t=()=>{for(;this.children.length>1;)this.removeChild(this.lastChild)};t(),this.mm.add(this.breakpoint,(()=>{if(this.children.length>0){let t=Math.ceil(this.clientWidth/this.children[0].scrollWidth);for(let e=1;e<t+2;e++){let t=this.firstElementChild,e=t.cloneNode(!0);t.parentNode.append(e)}}return()=>{t()}}))}skewed(){this.skew&&this.mm.add(this.breakpoint,(()=>{let t=this.skew<0?-1*this.skew:this.skew;return this.style.transformOrigin="center center",this.style.transform=`skew(0deg, ${this.skew}deg)`,this.style.minHeight=`calc(${1.25*t}vh + ${1.25*t}vw)`,()=>{this.style.removeProperty("transform-origin"),this.style.removeProperty("transform"),this.style.removeProperty("min-height")}}))}marquee(){this.mm.add(this.breakpoint,(()=>{this.tl=gsap.timeline(),gsap.config({nullTargetWarn:!1}),this.tl.paused(!0),gsap.set(this.children,{"will-change":"transform"}),this.tl.to(this.children,{duration:this.dur,x:"-100%",ease:"none",repeat:-1}).timeScale("ltr"===this.dir?-1:1).totalProgress(.5),ScrollTrigger.create({trigger:this,start:"top bottom",end:"bottom top",onEnter:()=>this.tl.resume(),onLeave:()=>this.tl.pause(),onEnterBack:()=>this.tl.resume(),onLeaveBack:()=>this.tl.pause()})}))}scrollReverse(){"auto"===this.dir&&this.mm.add(this.breakpoint,(()=>{let t=0,e=1;window.addEventListener("scroll",(()=>{let i=window.pageYOffset>t?1:-1;i!==e&&(gsap.to(this.tl,{timeScale:i,overwrite:!0}),e=i),t=window.pageYOffset}))}))}debounce(t,e){let i;return(...s)=>{i&&clearTimeout(i),i=setTimeout((()=>t(...s)),e)}}resizing(){const t=()=>{this.mm.add(this.breakpoint,(()=>{this.tl.kill(),this.tl=null,gsap.set(this.children,{clearProps:!0}),this.cloning(),this.marquee()}))};this.mm.add("(any-pointer: coarse)",(()=>{window.matchMedia("(orientation: portrait)").addEventListener("change",this.debounce((e=>{e.matches||t()}),250))})),this.mm.add("(any-pointer: fine)",(()=>{window.addEventListener("resize",this.debounce((()=>{t()}),250))}))}}customElements.get("marquee-content")||customElements.define("marquee-content",t),new t})();
1
+ (()=>{"use strict";(()=>{const e=document.querySelectorAll(".marquee-content");for(const t of e){let e,r=gsap.matchMedia(),a=t.dataset.mcDuration||20,n=t.dataset.mcSkew,o=t.dataset.mcMax,i=t.dataset.mcMin,s=t.dataset.mcDirection;const l=(e,t)=>{let r;return(...a)=>{r&&clearTimeout(r),r=setTimeout((()=>e(...a)),t)}},d=()=>{const a=()=>{for(;t.children.length>1;)t.removeChild(t.lastChild)};a(),r.add(e,(()=>{if(t.children.length>0){let e=Math.ceil(t.clientWidth/t.children[0].scrollWidth);for(let r=1;r<e+2;r++){let e=t.firstElementChild,r=e.cloneNode(!0);e.parentNode.append(r)}}return()=>{a()}}))},c=()=>{n&&r.add(e,(()=>{let e=n<0?-1*n:n;return t.style.transformOrigin="center center",t.style.transform=`skew(0deg, ${n}deg)`,t.style.minHeight=`calc(${1.25*e}vh + ${1.25*e}vw)`,()=>{t.style.removeProperty("transform-origin"),t.style.removeProperty("transform"),t.style.removeProperty("min-height")}}))},m=()=>{r.add(e,(()=>{gsap.config({nullTargetWarn:!1}),gsap.set(t.children,{"will-change":"transform"});let e=gsap.to(t.children,{duration:a,x:"-100%",ease:"none",repeat:-1,scrollTrigger:{trigger:t,start:"top bottom",end:"bottom top",toggleActions:"resume pause resume pause"}}).totalProgress(.5),r=0;let n;"ltr"===s?n=!0:"auto"===s&&window.addEventListener("scroll",(()=>{let t=!1,a=window.pageYOffset;a>r&&(t=!0),r=a,gsap.to(e,{timeScale:t?-1:1,overwrite:!0})}),{capture:!0,passive:!0}),gsap.to(e,{timeScale:n?-1:1,overwrite:!0})}))},g=()=>{const e=()=>{let e=gsap.timeline();e.kill(),e=null,gsap.set(t.children,{clearProps:!0}),d(),m()};r.add("(any-pointer: coarse)",(()=>{window.matchMedia("(orientation: portrait)").addEventListener("change",l((t=>{t.matches||e()}),250))})),r.add("(any-pointer: fine)",(()=>{window.addEventListener("resize",l((()=>{e()}),250))}))};(()=>{o||i?(o&&(e=`(max-width: ${o-.02}px)`),i&&(e=`(min-width: ${i}px)`)):e=""})(),d(),c(),m(),g()}})()})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "1.1.1",
4
- "description": "Marquee content with GSAP",
3
+ "version": "1.3.0",
4
+ "description": "Infinite marquee animation with GSAP",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -37,6 +37,6 @@
37
37
  "webpack-stream": "^7.0.0"
38
38
  },
39
39
  "keywords": [
40
- "marquee"
40
+ "marquee animation"
41
41
  ]
42
42
  }
package/src/index.html CHANGED
@@ -11,7 +11,7 @@
11
11
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12
12
  <link href="https://fonts.googleapis.com/css2?family=Alkatra:wght@700&family=Anton&family=Lobster&family=PT+Sans+Narrow:wght@700&family=Prompt:wght@500&display=swap" rel="stylesheet">
13
13
  <style type="text/css">
14
- 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: 150px 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: 80px auto 30px;padding: 0 20px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
14
+ 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: 150px 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: 80px auto 30px;padding: 0 20px;max-width: 1400px}.data-code strong{display: inline-flex;padding: 5px 12px;border: 1px dotted #ccc}
15
15
  </style>
16
16
  </head>
17
17
  <body>
@@ -20,7 +20,7 @@
20
20
  <p>The basic version, with scrolling content from right to left</p>
21
21
  </section>
22
22
  <section class="example-1">
23
- <marquee-content
23
+ <div class="marquee-content"
24
24
  data-mc-duration="60"
25
25
  role="marquee">
26
26
  <ul class="font alkatra">
@@ -33,10 +33,10 @@
33
33
  <li>Vomero</li>
34
34
  <li>Pegasus</li>
35
35
  </ul>
36
- </marquee-content>
36
+ </div>
37
37
  </section>
38
38
  <section class="example-7">
39
- <marquee-content
39
+ <div class="marquee-content"
40
40
  data-mc-duration="20"
41
41
  role="marquee">
42
42
  <ul>
@@ -45,14 +45,14 @@
45
45
  <li><img src="//fastly.picsum.photos/id/235/180/100.jpg?hmac=5KlYbDb93R7me0GThn6FFoK_OZ8ziPn-fb98FHIMb5c" alt></li>
46
46
  <li><img src="//fastly.picsum.photos/id/1050/180/100.jpg?hmac=f9i0nGYKBetkohJors44GETXmUhSbLcXMUlSvMCluJY" alt></li>
47
47
  </ul>
48
- </marquee-content>
48
+ </div>
49
49
  </section>
50
50
  <section class="data-code">
51
51
  <strong>data-mc-duration=&quot;60&quot; data-mc-direction=&quot;ltr&quot;</strong>
52
52
  <p><code>data-mc-direction="ltr"</code> &mdash; changes the scroll direction from left to right</p>
53
53
  </section>
54
54
  <section class="example-2">
55
- <marquee-content
55
+ <div class="marquee-content"
56
56
  data-mc-duration="60"
57
57
  data-mc-direction="ltr"
58
58
  role="marquee">
@@ -67,14 +67,14 @@
67
67
  <li><span class="font anton">Vomero</span></li>
68
68
  <li><span class="font pt">Pegasus</span></li>
69
69
  </ul>
70
- </marquee-content>
70
+ </div>
71
71
  </section>
72
72
  <section class="data-code">
73
73
  <strong>data-mc-duration=&quot;60&quot; data-mc-direction=&quot;auto&quot;</strong>
74
74
  <p><code>data-mc-direction="auto"</code> &mdash; automatically changes the scrolling direction of the component when scrolling the page</p>
75
75
  </section>
76
76
  <section class="example-3">
77
- <marquee-content
77
+ <div class="marquee-content"
78
78
  data-mc-duration="60"
79
79
  data-mc-direction="auto"
80
80
  role="marquee">
@@ -89,14 +89,14 @@
89
89
  <li>Vomero</li>
90
90
  <li>Pegasus</li>
91
91
  </ul>
92
- </marquee-content>
92
+ </div>
93
93
  </section>
94
94
  <section class="data-code">
95
95
  <strong>data-mc-duration=&quot;60&quot; data-mc-skew=&quot;-4&quot;</strong>
96
96
  <p><code>data-mc-skew="-4"</code> &mdash; transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value)</p>
97
97
  </section>
98
98
  <section class="example-4">
99
- <marquee-content
99
+ <div class="marquee-content"
100
100
  data-mc-duration="60"
101
101
  data-mc-skew="-4"
102
102
  role="marquee">
@@ -111,35 +111,35 @@
111
111
  <li>Vomero</li>
112
112
  <li>Pegasus</li>
113
113
  </ul>
114
- </marquee-content>
114
+ </div>
115
115
  </section>
116
116
  <section class="data-code">
117
117
  <strong>data-mc-duration=&quot;5&quot; data-mc-min=&quot;992&quot;</strong>
118
118
  <p><code>data-mc-min="992"</code> &mdash; sets the minimum screen 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)</p>
119
119
  </section>
120
120
  <section class="example-5">
121
- <marquee-content
121
+ <div class="marquee-content"
122
122
  data-mc-duration="5"
123
123
  data-mc-min="992"
124
124
  role="marquee">
125
125
  <ul class="font pt">
126
126
  <li>Jordan</li>
127
127
  </ul>
128
- </marquee-content>
128
+ </div>
129
129
  </section>
130
130
  <section class="data-code">
131
131
  <strong>data-mc-duration=&quot;5&quot; data-mc-max=&quot;992&quot;</strong>
132
132
  <p><code>data-mc-max="992"</code> &mdash; sets the maximum screen 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)</p>
133
133
  </section>
134
134
  <section class="example-6">
135
- <marquee-content
135
+ <div class="marquee-content"
136
136
  data-mc-duration="5"
137
137
  data-mc-max="992"
138
138
  role="marquee">
139
139
  <ul class="font pt">
140
140
  <li>Presto</li>
141
141
  </ul>
142
- </marquee-content>
142
+ </div>
143
143
  </section>
144
144
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/gsap.min.js"></script>
145
145
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/ScrollTrigger.min.js"></script>
package/src/js/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { MarqueeContent } from './marquee-content.js'
2
2
 
3
- new MarqueeContent()
3
+ MarqueeContent()
@@ -1,177 +1,184 @@
1
- export class MarqueeContent extends HTMLElement {
2
- constructor() {
3
- super()
4
-
5
- this.mm = gsap.matchMedia()
6
- this.tl = gsap.timeline()
7
- this.dur = this.dataset.mcDuration || 20
8
- this.skew = this.dataset.mcSkew
9
- this.max = this.dataset.mcMax
10
- this.min = this.dataset.mcMin
11
- this.dir = this.dataset.mcDirection
12
-
13
- this.breakpoints()
14
- this.cloning()
15
- this.skewed()
16
- this.marquee()
17
- this.scrollReverse()
18
- this.debounce()
19
- this.resizing()
20
- }
21
-
22
- breakpoints() {
23
- if(this.max || this.min) {
24
- if(this.max) {
25
- this.breakpoint = `(max-width: ${this.max - 0.02}px)`
26
- }
27
-
28
- if(this.min) {
29
- this.breakpoint = `(min-width: ${this.min}px)`
1
+ const MarqueeContent = () => {
2
+ const items = document.querySelectorAll('.marquee-content')
3
+
4
+ for (const item of items) {
5
+ let matchMedia = gsap.matchMedia(),
6
+ duration = item.dataset.mcDuration || 20,
7
+ skew = item.dataset.mcSkew,
8
+ maxWidth = item.dataset.mcMax,
9
+ minWidth = item.dataset.mcMin,
10
+ direction = item.dataset.mcDirection,
11
+ breakpoint
12
+
13
+ const
14
+
15
+ debounce = (fn, delay) => {
16
+ let timer
17
+
18
+ return (...args) => {
19
+ if (timer) clearTimeout(timer)
20
+ timer = setTimeout(() => fn(...args), delay)
30
21
  }
31
- } else {
32
- this.breakpoint = ``
33
- }
34
- }
35
-
36
- cloning() {
37
- const removingClones = () => {
38
- while (this.children.length > 1) {
39
- this.removeChild(this.lastChild)
40
- }
41
- }
42
-
43
- removingClones()
44
-
45
- this.mm.add(this.breakpoint, () => {
46
- if (this.children.length > 0) {
47
- let requiredQuantity = Math.ceil(this.clientWidth / this.children[0].scrollWidth)
22
+ },
48
23
 
49
- for (let i = 1; i < (requiredQuantity) + 2; i++) {
50
- let item = this.firstElementChild
51
- let clone = item.cloneNode(true)
52
- item.parentNode.append(clone)
24
+ breakpoints = () => {
25
+ if(maxWidth || minWidth) {
26
+ if(maxWidth) {
27
+ breakpoint = `(max-width: ${maxWidth - 0.02}px)`
53
28
  }
54
- }
55
29
 
56
- return () => {
57
- removingClones()
30
+ if(minWidth) {
31
+ breakpoint = `(min-width: ${minWidth}px)`
32
+ }
33
+ } else {
34
+ breakpoint = ``
58
35
  }
59
- })
60
- }
61
-
62
- skewed() {
63
- if(!this.skew) { return }
64
-
65
- this.mm.add(this.breakpoint, () => {
66
- let abs = (this.skew < 0) ? this.skew * -1 : this.skew
36
+ },
67
37
 
68
- this.style.transformOrigin = `center center`
69
- this.style.transform = `skew(0deg, ${this.skew}deg)`
70
- this.style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
71
-
72
- return () => {
73
- this.style.removeProperty('transform-origin')
74
- this.style.removeProperty('transform')
75
- this.style.removeProperty('min-height')
38
+ cloning = () => {
39
+ const removingClones = () => {
40
+ while (item.children.length > 1) {
41
+ item.removeChild(item.lastChild)
42
+ }
76
43
  }
77
- })
78
- }
79
44
 
80
- marquee() {
81
- this.mm.add(this.breakpoint, () => {
82
- this.tl = gsap.timeline()
83
-
84
- gsap.config({
85
- nullTargetWarn: false
86
- })
45
+ removingClones()
87
46
 
88
- this.tl.paused(true)
47
+ matchMedia.add(breakpoint, () => {
48
+ if (item.children.length > 0) {
49
+ let requiredQuantity = Math.ceil(item.clientWidth / item.children[0].scrollWidth)
89
50
 
90
- gsap.set(this.children, {
91
- 'will-change': 'transform'
92
- })
51
+ for (let i = 1; i < (requiredQuantity) + 2; i++) {
52
+ let cloned = item.firstElementChild
53
+ let clone = cloned.cloneNode(true)
54
+ cloned.parentNode.append(clone)
55
+ }
56
+ }
93
57
 
94
- this.tl.to(this.children, {
95
- duration: this.dur,
96
- x: '-100%',
97
- ease: 'none',
98
- repeat: -1
99
- }).timeScale(this.dir === 'ltr' ? -1 : 1).totalProgress(.5)
100
-
101
- ScrollTrigger.create({
102
- trigger: this,
103
- start: 'top bottom',
104
- end: 'bottom top',
105
- onEnter: () => this.tl.resume(),
106
- onLeave: () => this.tl.pause(),
107
- onEnterBack: () => this.tl.resume(),
108
- onLeaveBack: () => this.tl.pause()
58
+ return () => {
59
+ removingClones()
60
+ }
109
61
  })
110
- })
111
- }
62
+ },
112
63
 
113
- scrollReverse() {
114
- if(this.dir !== 'auto') { return }
64
+ skewed = () => {
65
+ if(!skew) { return }
115
66
 
116
- this.mm.add(this.breakpoint, () => {
117
- let currentScroll = 0,
118
- scrollDirection = 1
67
+ matchMedia.add(breakpoint, () => {
68
+ let abs = (skew < 0) ? skew * -1 : skew
119
69
 
120
- window.addEventListener('scroll', () => {
121
- let orientation = (window.pageYOffset > currentScroll) ? 1 : -1
70
+ item.style.transformOrigin = `center center`
71
+ item.style.transform = `skew(0deg, ${skew}deg)`
72
+ item.style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
122
73
 
123
- if (orientation !== scrollDirection) {
124
- gsap.to(this.tl, {
125
- timeScale: orientation,
74
+ return () => {
75
+ item.style.removeProperty('transform-origin')
76
+ item.style.removeProperty('transform')
77
+ item.style.removeProperty('min-height')
78
+ }
79
+ })
80
+ },
81
+
82
+ marquee = () => {
83
+ matchMedia.add(breakpoint, () => {
84
+ gsap.config({
85
+ nullTargetWarn: false
86
+ })
87
+
88
+ gsap.set(item.children, {
89
+ 'will-change': 'transform'
90
+ })
91
+
92
+ let tween = gsap.to(item.children, {
93
+ duration: duration,
94
+ x: '-100%',
95
+ ease: 'none',
96
+ repeat: -1,
97
+ scrollTrigger: {
98
+ trigger: item,
99
+ start: 'top bottom',
100
+ end: 'bottom top',
101
+ toggleActions: 'resume pause resume pause'
102
+ },
103
+ }).totalProgress(.5)
104
+
105
+ // TODO refactoring of the content scrolling direction
106
+ let previousScrollPosition = 0
107
+
108
+ const isScrollingDown = () => {
109
+ let someCondition = false
110
+
111
+ let scrollPosition = window.pageYOffset
112
+
113
+ if (scrollPosition > previousScrollPosition) {
114
+ someCondition = true
115
+ }
116
+
117
+ previousScrollPosition = scrollPosition
118
+
119
+ gsap.to(tween, {
120
+ timeScale: someCondition ? -1 : 1,
126
121
  overwrite: true
127
122
  })
123
+ }
124
+
125
+ let someCondition
128
126
 
129
- scrollDirection = orientation
127
+ if(direction === 'ltr') {
128
+ someCondition = true
129
+ } else if(direction === 'auto') {
130
+ window.addEventListener('scroll', isScrollingDown, { capture: true, passive: true })
130
131
  }
131
132
 
132
- currentScroll = window.pageYOffset
133
+ gsap.to(tween, {
134
+ timeScale: someCondition ? -1 : 1,
135
+ overwrite: true
136
+ })
133
137
  })
134
- })
135
- }
138
+ },
136
139
 
137
- debounce(fn, delay) {
138
- let timer
140
+ resizing = () => {
141
+ const resetAnimation = () => {
142
+ let tl = gsap.timeline()
139
143
 
140
- return (...args) => {
141
- if (timer) clearTimeout(timer)
142
- timer = setTimeout(() => fn(...args), delay)
143
- }
144
- }
144
+ tl.kill()
145
+ tl = null
145
146
 
146
- resizing() {
147
- const resetAnimation = () => {
148
- this.mm.add(this.breakpoint, () => {
149
- this.tl.kill()
150
- this.tl = null
147
+ gsap.set(item.children, { clearProps: true })
151
148
 
152
- gsap.set(this.children, { clearProps: true })
149
+ cloning()
150
+ marquee()
151
+ }
153
152
 
154
- this.cloning()
155
- this.marquee()
156
- })
157
- }
153
+ matchMedia.add('(any-pointer: coarse)', () => {
154
+ let portrait = window.matchMedia('(orientation: portrait)')
158
155
 
159
- this.mm.add('(any-pointer: coarse)', () => {
160
- let portrait = window.matchMedia('(orientation: portrait)')
156
+ portrait.addEventListener('change', debounce((e) => {
157
+ if(!e.matches) {
158
+ resetAnimation()
159
+ }
160
+ }, 250))
161
+ })
161
162
 
162
- portrait.addEventListener('change', this.debounce((e) => {
163
- if(!e.matches) {
163
+ matchMedia.add('(any-pointer: fine)', () => {
164
+ window.addEventListener('resize', debounce(() => {
164
165
  resetAnimation()
165
- }
166
- }, 250))
167
- })
168
-
169
- this.mm.add('(any-pointer: fine)', () => {
170
- window.addEventListener('resize', this.debounce(() => {
171
- resetAnimation()
172
- }, 250))
173
- })
166
+ }, 250))
167
+ })
168
+ },
169
+
170
+ init = () => {
171
+ breakpoints()
172
+ cloning()
173
+ skewed()
174
+ marquee()
175
+ resizing()
176
+ }
177
+
178
+ init()
174
179
  }
175
180
  }
176
181
 
177
- customElements.get('marquee-content') || customElements.define('marquee-content', MarqueeContent)
182
+ export {
183
+ MarqueeContent
184
+ }