marquee-content 0.0.1 → 0.0.3

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
@@ -7,13 +7,9 @@
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>Marquee content with GSAP</p>
10
+ <sup><a href="https://bundlephobia.com/package/marquee-content@0.0.2">1Kb gzipped</a></sup>
11
11
 
12
- <p>
13
- <a href="https://ux-ui-pro.github.io/marquee-content/dist/">Demo</a>
14
- <br>
15
- <a href="https://github.com/ux-ui-pro/marquee-content/releases/latest">Download</a>
16
- </p>
12
+ <h3><a href="https://ux-ui-pro.github.io/marquee-content/dist/">Demo</a></h3>
17
13
 
18
14
  </div>
19
15
  <br>
@@ -26,6 +22,7 @@ $ yarn add marquee-content
26
22
  ```javascript
27
23
  $ npm i marquee-content
28
24
  ```
25
+
29
26
  <br>
30
27
 
31
28
  ### Import
@@ -34,5 +31,34 @@ import { MarqueeContent } from 'marquee-content'
34
31
  ```
35
32
  <br>
36
33
 
34
+ ### Usage
35
+ ```HTML
36
+ <marquee-content
37
+ data-mc-clone="3"
38
+ data-mc-speed="60"
39
+ role="marquee">
40
+ <ul>
41
+ <li>Primary</li>
42
+ <li>Secondary</li>
43
+ <li>Tertiary</li>
44
+ <li>Quaternary</li>
45
+ </ul>
46
+ </marquee-content>
47
+ ```
48
+ <br>
49
+
50
+ ### Settings
51
+
52
+ | 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; | Default | Description |
53
+ | --- | --- | --- |
54
+ | `data-mc-clone` | ... | Clones the content of the component the specified number of times. |
55
+ | `data-mc-speed` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
56
+ | `data-mc-direction` | `rtl` | `ltr` changes the scroll direction from left to right<br>`auto` automatically changes the scrolling direction of the component when scrolling the page. |
57
+ | `data-mc-skew` | ... | Transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value). |
58
+ | `data-mc-min` | ... | 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` | ... | data-mc-max="1200" — 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). |
60
+
61
+ <br>
62
+
37
63
  ### License
38
64
  marquee-content is released under MIT license
package/dist/index.html CHANGED
@@ -7,6 +7,9 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
8
8
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
9
9
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
10
+ <link rel="preconnect" href="https://fonts.googleapis.com">
11
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
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">
10
13
  <style type="text/css">
11
14
  html {
12
15
  font-family: system-ui, -apple-system, "Open Sans", "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
@@ -14,11 +17,12 @@
14
17
  }
15
18
 
16
19
  body {
17
- margin: 0;
20
+ margin: 150px 0 500px;
18
21
  font-feature-settings: "kern" 1,"liga" 0;
19
22
  font-size: 1.6rem;
20
23
  font-weight: 400;
21
24
  line-height: 1.5;
25
+ color: #444;
22
26
  }
23
27
 
24
28
  html,
@@ -29,71 +33,271 @@
29
33
  -webkit-font-smoothing: subpixel-antialiased;
30
34
  }
31
35
 
32
- .layout {
33
- max-width: 120rem;
34
- margin: 0 auto;
35
- border: 1px solid red;
36
- border-top: none;
37
- border-bottom: none;
36
+ marquee-content {
37
+ pointer-events: none;
38
+ max-width: 100vw;
39
+ justify-content: center;
40
+ align-items: center;
41
+ display: flex;
42
+ position: relative;
43
+ overflow: hidden;
44
+ }
45
+
46
+ .font {
47
+ white-space: nowrap;
48
+ }
49
+
50
+ .alkatra {
51
+ font-family: 'Alkatra', cursive;
52
+ font-weight: 700;
53
+ font-size: 48px;
54
+ }
55
+
56
+ .anton {
57
+ font-family: 'Anton', sans-serif;
58
+ font-weight: 700;
59
+ font-size: 40px;
60
+ }
61
+
62
+ .pt {
63
+ font-family: 'PT Sans Narrow', sans-serif;
64
+ font-weight: 400;
65
+ font-size: 52px;
66
+ }
67
+
68
+ .lobster {
69
+ font-family: 'Lobster', cursive;
70
+ font-weight: 400;
71
+ font-size: 50px;
72
+ }
73
+
74
+ .prompt {
75
+ font-family: 'Prompt', sans-serif;
76
+ font-weight: 500;
77
+ font-size: 48px;
38
78
  }
39
79
 
40
80
  ul {
41
- display: flex;
42
- list-style: none;
43
- margin: 0; padding: 0;
81
+ list-style: none;
82
+ margin: 0; padding: 0;
83
+ display: flex;
84
+ align-items: center;
44
85
  }
45
86
 
46
87
  li {
47
- width: 200px;
48
- margin: 0 20px;
49
- background: lightgray;
50
- text-align: center;
88
+ padding: 0 10px;
89
+ text-align: center;
51
90
  }
52
91
 
53
- marquee-content {
54
- pointer-events: none;
55
- max-width: 100vw;
56
- justify-content: center;
57
- align-items: center;
58
- display: flex;
92
+ .example-1 {
93
+
94
+ }
95
+
96
+ .example-1 li {
97
+ padding: 0 0 0 66px;
98
+ background:
99
+ url("data:image/svg+xml,%3Csvg width='26' height='26' viewBox='0 0 26 26' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15.0527 10.9474L13 0L10.9473 10.9474L0 13L10.9473 15.0526L13 26L15.0527 15.0526L26 13L15.0527 10.9474Z' fill='%23444444'/%3E%3C/svg%3E")
100
+ center left 20px / 26px 26px
101
+ no-repeat;
102
+ }
103
+
104
+ .example-2 {
105
+
106
+ }
107
+
108
+ .example-2 li {
109
+ padding: 0 15px;
110
+ }
111
+
112
+ .example-3 {
113
+
114
+ }
115
+
116
+ .example-3 li {
59
117
  position: relative;
60
- overflow: hidden;
118
+ padding: 0 0 0 56px;
119
+ }
120
+
121
+ .example-3 li::before {
122
+ content: '';
123
+ position: absolute;
124
+ top: 0; right: -33px; bottom: 0; left: auto;
125
+ margin: auto;
126
+ width: 7px; height: 7px;
127
+ transform: translateY(5px);
128
+ background: #444;
129
+ border-radius: 100%;
130
+ }
131
+
132
+ .example-4 {
133
+ text-transform: uppercase;
134
+ }
135
+
136
+ .example-5 {
137
+
138
+ }
139
+
140
+ .example-6 {
141
+
142
+ }
143
+
144
+ .data-code {
145
+ margin: 80px auto 30px;
146
+ padding: 0 20px;
147
+ max-width: 1400px;
148
+ }
149
+
150
+ .data-code strong {
151
+ display: inline-flex;
152
+ padding: 5px 12px;
153
+ border: 1px dotted #ccc;
61
154
  }
62
155
  </style>
63
156
  </head>
64
157
  <body>
65
- <div class="layout">
158
+ <section class="data-code">
159
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;50&quot;</strong>
160
+ <p>The basic version, with scrolling content from right to left (in this example, 3 clones of scrollable content are added, scrolling lasts 50 seconds)</p>
161
+ </section>
162
+ <section class="example-1">
163
+ <marquee-content
164
+ data-mc-clone="3"
165
+ data-mc-speed="50"
166
+ role="marquee">
167
+ <ul class="font alkatra">
168
+ <li>Monarch</li>
169
+ <li>Benassi</li>
170
+ <li>Air Max</li>
171
+ <li>Cortez</li>
172
+ <li>Jordan</li>
173
+ <li>Presto</li>
174
+ <li>Roshe</li>
175
+ <li>Tempo</li>
176
+ <li>Vomero</li>
177
+ <li>Pegasus</li>
178
+ </ul>
179
+ </marquee-content>
180
+ </section>
181
+ <section class="data-code">
182
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;70&quot; data-mc-direction=&quot;ltr&quot;</strong>
183
+ <p><code>data-mc-direction="ltr"</code> &mdash; changes the scroll direction from left to right</p>
184
+ </section>
185
+ <section class="example-2">
186
+ <marquee-content
187
+ data-mc-clone="3"
188
+ data-mc-speed="70"
189
+ data-mc-direction="ltr"
190
+ role="marquee">
191
+ <ul>
192
+ <li><span class="font anton">Monarch</span></li>
193
+ <li><span class="font pt">Benassi</span></li>
194
+ <li><span class="font lobster">Air Max</span></li>
195
+ <li><span class="font prompt">Cortez</span></li>
196
+ <li><span class="font anton">Jordan</span></li>
197
+ <li><span class="font pt">Presto</span></li>
198
+ <li><span class="font lobster">Roshe</span></li>
199
+ <li><span class="font prompt">Tempo</span></li>
200
+ <li><span class="font anton">Vomero</span></li>
201
+ <li><span class="font pt">Pegasus</span></li>
202
+ </ul>
203
+ </marquee-content>
204
+ </section>
205
+ <section class="data-code">
206
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-direction=&quot;auto&quot;</strong>
207
+ <p><code>data-mc-direction="auto"</code> &mdash; automatically changes the scrolling direction of the component when scrolling the page</p>
208
+ </section>
209
+ <section class="example-3">
210
+ <marquee-content
211
+ data-mc-clone="3"
212
+ data-mc-speed="60"
213
+ data-mc-direction="auto"
214
+ role="marquee">
215
+ <ul class="font lobster">
216
+ <li>Monarch</li>
217
+ <li>Benassi</li>
218
+ <li>Air Max</li>
219
+ <li>Cortez</li>
220
+ <li>Jordan</li>
221
+ <li>Presto</li>
222
+ <li>Roshe</li>
223
+ <li>Tempo</li>
224
+ <li>Vomero</li>
225
+ <li>Pegasus</li>
226
+ </ul>
227
+ </marquee-content>
228
+ </section>
229
+ <section class="data-code">
230
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-skew=&quot;-3&quot;</strong>
231
+ <p><code>data-mc-skew="-3"</code> &mdash; transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value)</p>
232
+ </section>
233
+ <section class="example-4">
234
+ <marquee-content
235
+ data-mc-clone="3"
236
+ data-mc-speed="60"
237
+ data-mc-skew="-3"
238
+ role="marquee">
239
+ <ul class="font pt">
240
+ <li>Monarch</li>
241
+ <li>Benassi</li>
242
+ <li>Air Max</li>
243
+ <li>Cortez</li>
244
+ <li>Jordan</li>
245
+ <li>Presto</li>
246
+ <li>Roshe</li>
247
+ <li>Tempo</li>
248
+ <li>Vomero</li>
249
+ <li>Pegasus</li>
250
+ </ul>
251
+ </marquee-content>
252
+ </section>
253
+ <section class="data-code">
254
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-min=&quot;1200&quot;</strong>
255
+ <p><code>data-mc-min="1200"</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>
256
+ </section>
257
+ <section class="example-5">
258
+ <marquee-content
259
+ data-mc-clone="3"
260
+ data-mc-speed="60"
261
+ data-mc-min="1200"
262
+ role="marquee">
263
+ <ul class="font pt">
264
+ <li>Monarch</li>
265
+ <li>Benassi</li>
266
+ <li>Air Max</li>
267
+ <li>Cortez</li>
268
+ <li>Jordan</li>
269
+ <li>Presto</li>
270
+ <li>Roshe</li>
271
+ <li>Tempo</li>
272
+ <li>Vomero</li>
273
+ <li>Pegasus</li>
274
+ </ul>
275
+ </marquee-content>
276
+ </section>
277
+ <section class="data-code">
278
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-max=&quot;1200&quot;</strong>
279
+ <p><code>data-mc-max="1200"</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>
280
+ </section>
281
+ <section class="example-6">
66
282
  <marquee-content
67
- data-mc-min="1600"
68
- data-mc-clone="2"
69
- data-mc-speed="30"
70
- data-mc-skew="-2.4"
283
+ data-mc-clone="3"
284
+ data-mc-speed="60"
285
+ data-mc-max="1200"
71
286
  role="marquee">
72
- <ul class="logo-set">
73
- <li class="logo-set__item">
74
- 1
75
- </li>
76
- <li class="logo-set__item">
77
- 2
78
- </li>
79
- <li class="logo-set__item">
80
- 3
81
- </li>
82
- <li class="logo-set__item">
83
- 4
84
- </li>
85
- <li class="logo-set__item">
86
- 5
87
- </li>
88
- <li class="logo-set__item">
89
- 6
90
- </li>
91
- <li class="logo-set__item">
92
- 7
93
- </li>
287
+ <ul class="font pt">
288
+ <li>Monarch</li>
289
+ <li>Benassi</li>
290
+ <li>Air Max</li>
291
+ <li>Cortez</li>
292
+ <li>Jordan</li>
293
+ <li>Presto</li>
294
+ <li>Roshe</li>
295
+ <li>Tempo</li>
296
+ <li>Vomero</li>
297
+ <li>Pegasus</li>
94
298
  </ul>
95
299
  </marquee-content>
96
- </div>
300
+ </section>
97
301
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/gsap.min.js"></script>
98
302
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/ScrollTrigger.min.js"></script>
99
303
  <script src="js/marquee-content.min.js"></script>
@@ -1 +1 @@
1
- (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.speed=this.dataset.mcSpeed||20,this.clone=this.dataset.mcClone,this.skew=this.dataset.mcSkew,this.abs=this.skew<0?-1*this.skew:this.skew,this.max=this.dataset.mcMax,this.min=this.dataset.mcMin,this.mm=gsap.matchMedia(),this.breakpoints(),this.cloning(),this.skewed(),this.animate()}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="(min-width: 100vw)"}cloning(){this.clone&&this.mm.add(this.breakpoint,(()=>{for(let t=0;t<this.clone;t++){let t=this.firstElementChild,e=t.cloneNode(!0);t.after(e)}return()=>{for(;this.children.length>1;)this.removeChild(this.lastChild)}}))}skewed(){this.skew&&this.mm.add(this.breakpoint,(()=>{gsap.set(this,{skewY:this.skew,"transform-origin":"center center","min-height":`calc(${1.25*this.abs}vh + ${1.25*this.abs}vw)`})}))}animate(){this.mm.add(this.breakpoint,(()=>{gsap.defaults({overwrite:!0}),gsap.set(this.children,{"will-change":"transform"});let t=gsap.to(this.children,{duration:this.speed,x:"-100%",ease:"none",repeat:-1,scrollTrigger:{trigger:this,toggleActions:"play pause play pause",start:"-=50% bottom",end:"bottom top",onUpdate:({direction:e})=>{1===e?t.timeScale(1):t.timeScale(-1)}}}).timeScale(1).totalProgress(.5)}))}}customElements.get("marquee-content")||customElements.define("marquee-content",t),new t})();
1
+ (()=>{"use strict";class t extends HTMLElement{constructor(){super(),this.mm=gsap.matchMedia(),this.tl=gsap.timeline(),this.speed=this.dataset.mcSpeed||20,this.clone=this.dataset.mcClone,this.skew=this.dataset.mcSkew,this.abs=this.skew<0?-1*this.skew:this.skew,this.max=this.dataset.mcMax,this.min=this.dataset.mcMin,this.dir=this.dataset.mcDirection,this.breakpoints(),this.cloning(),this.skewed(),this.marquee(),this.reverse()}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="(min-width: 100vw)"}cloning(){this.clone&&this.mm.add(this.breakpoint,(()=>{for(let t=0;t<this.clone;t++){let t=this.firstElementChild,e=t.cloneNode(!0);t.after(e)}return()=>{for(;this.children.length>1;)this.removeChild(this.lastChild)}}))}skewed(){this.skew&&this.mm.add(this.breakpoint,(()=>(this.style.minHeight=`calc(${1.25*this.abs}vh + ${1.25*this.abs}vw)`,this.style.transformOrigin="center center",this.style.transform=`skew(0deg, ${this.skew}deg)`,()=>{this.style.removeProperty("min-height"),this.style.removeProperty("transform-origin"),this.style.removeProperty("transform")})))}marquee(){this.mm.add(this.breakpoint,(()=>{gsap.config({nullTargetWarn:!1}),this.tl.paused(!0),gsap.set(this.children,{"will-change":"transform"}),this.tl.to(this.children,{duration:this.speed,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()})}))}reverse(){"auto"===this.dir&&this.mm.add(this.breakpoint,(()=>{let t=0,e=1;window.addEventListener("scroll",(()=>{let s=window.pageYOffset>t?1:-1;s!==e&&(gsap.to(this.tl,{timeScale:s,overwrite:!0}),e=s),t=window.pageYOffset}))}))}}customElements.get("marquee-content")||customElements.define("marquee-content",t),new t})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Marquee content with GSAP",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
package/src/index.html CHANGED
@@ -7,6 +7,9 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
8
8
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
9
9
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
10
+ <link rel="preconnect" href="https://fonts.googleapis.com">
11
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
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">
10
13
  <style type="text/css">
11
14
  html {
12
15
  font-family: system-ui, -apple-system, "Open Sans", "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
@@ -14,11 +17,12 @@
14
17
  }
15
18
 
16
19
  body {
17
- margin: 0;
20
+ margin: 150px 0 500px;
18
21
  font-feature-settings: "kern" 1,"liga" 0;
19
22
  font-size: 1.6rem;
20
23
  font-weight: 400;
21
24
  line-height: 1.5;
25
+ color: #444;
22
26
  }
23
27
 
24
28
  html,
@@ -29,71 +33,271 @@
29
33
  -webkit-font-smoothing: subpixel-antialiased;
30
34
  }
31
35
 
32
- .layout {
33
- max-width: 120rem;
34
- margin: 0 auto;
35
- border: 1px solid red;
36
- border-top: none;
37
- border-bottom: none;
36
+ marquee-content {
37
+ pointer-events: none;
38
+ max-width: 100vw;
39
+ justify-content: center;
40
+ align-items: center;
41
+ display: flex;
42
+ position: relative;
43
+ overflow: hidden;
44
+ }
45
+
46
+ .font {
47
+ white-space: nowrap;
48
+ }
49
+
50
+ .alkatra {
51
+ font-family: 'Alkatra', cursive;
52
+ font-weight: 700;
53
+ font-size: 48px;
54
+ }
55
+
56
+ .anton {
57
+ font-family: 'Anton', sans-serif;
58
+ font-weight: 700;
59
+ font-size: 40px;
60
+ }
61
+
62
+ .pt {
63
+ font-family: 'PT Sans Narrow', sans-serif;
64
+ font-weight: 400;
65
+ font-size: 52px;
66
+ }
67
+
68
+ .lobster {
69
+ font-family: 'Lobster', cursive;
70
+ font-weight: 400;
71
+ font-size: 50px;
72
+ }
73
+
74
+ .prompt {
75
+ font-family: 'Prompt', sans-serif;
76
+ font-weight: 500;
77
+ font-size: 48px;
38
78
  }
39
79
 
40
80
  ul {
41
- display: flex;
42
- list-style: none;
43
- margin: 0; padding: 0;
81
+ list-style: none;
82
+ margin: 0; padding: 0;
83
+ display: flex;
84
+ align-items: center;
44
85
  }
45
86
 
46
87
  li {
47
- width: 200px;
48
- margin: 0 20px;
49
- background: lightgray;
50
- text-align: center;
88
+ padding: 0 10px;
89
+ text-align: center;
51
90
  }
52
91
 
53
- marquee-content {
54
- pointer-events: none;
55
- max-width: 100vw;
56
- justify-content: center;
57
- align-items: center;
58
- display: flex;
92
+ .example-1 {
93
+
94
+ }
95
+
96
+ .example-1 li {
97
+ padding: 0 0 0 66px;
98
+ background:
99
+ url("data:image/svg+xml,%3Csvg width='26' height='26' viewBox='0 0 26 26' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15.0527 10.9474L13 0L10.9473 10.9474L0 13L10.9473 15.0526L13 26L15.0527 15.0526L26 13L15.0527 10.9474Z' fill='%23444444'/%3E%3C/svg%3E")
100
+ center left 20px / 26px 26px
101
+ no-repeat;
102
+ }
103
+
104
+ .example-2 {
105
+
106
+ }
107
+
108
+ .example-2 li {
109
+ padding: 0 15px;
110
+ }
111
+
112
+ .example-3 {
113
+
114
+ }
115
+
116
+ .example-3 li {
59
117
  position: relative;
60
- overflow: hidden;
118
+ padding: 0 0 0 56px;
119
+ }
120
+
121
+ .example-3 li::before {
122
+ content: '';
123
+ position: absolute;
124
+ top: 0; right: -33px; bottom: 0; left: auto;
125
+ margin: auto;
126
+ width: 7px; height: 7px;
127
+ transform: translateY(5px);
128
+ background: #444;
129
+ border-radius: 100%;
130
+ }
131
+
132
+ .example-4 {
133
+ text-transform: uppercase;
134
+ }
135
+
136
+ .example-5 {
137
+
138
+ }
139
+
140
+ .example-6 {
141
+
142
+ }
143
+
144
+ .data-code {
145
+ margin: 80px auto 30px;
146
+ padding: 0 20px;
147
+ max-width: 1400px;
148
+ }
149
+
150
+ .data-code strong {
151
+ display: inline-flex;
152
+ padding: 5px 12px;
153
+ border: 1px dotted #ccc;
61
154
  }
62
155
  </style>
63
156
  </head>
64
157
  <body>
65
- <div class="layout">
158
+ <section class="data-code">
159
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;50&quot;</strong>
160
+ <p>The basic version, with scrolling content from right to left (in this example, 3 clones of scrollable content are added, scrolling lasts 50 seconds)</p>
161
+ </section>
162
+ <section class="example-1">
163
+ <marquee-content
164
+ data-mc-clone="3"
165
+ data-mc-speed="50"
166
+ role="marquee">
167
+ <ul class="font alkatra">
168
+ <li>Monarch</li>
169
+ <li>Benassi</li>
170
+ <li>Air Max</li>
171
+ <li>Cortez</li>
172
+ <li>Jordan</li>
173
+ <li>Presto</li>
174
+ <li>Roshe</li>
175
+ <li>Tempo</li>
176
+ <li>Vomero</li>
177
+ <li>Pegasus</li>
178
+ </ul>
179
+ </marquee-content>
180
+ </section>
181
+ <section class="data-code">
182
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;70&quot; data-mc-direction=&quot;ltr&quot;</strong>
183
+ <p><code>data-mc-direction="ltr"</code> &mdash; changes the scroll direction from left to right</p>
184
+ </section>
185
+ <section class="example-2">
186
+ <marquee-content
187
+ data-mc-clone="3"
188
+ data-mc-speed="70"
189
+ data-mc-direction="ltr"
190
+ role="marquee">
191
+ <ul>
192
+ <li><span class="font anton">Monarch</span></li>
193
+ <li><span class="font pt">Benassi</span></li>
194
+ <li><span class="font lobster">Air Max</span></li>
195
+ <li><span class="font prompt">Cortez</span></li>
196
+ <li><span class="font anton">Jordan</span></li>
197
+ <li><span class="font pt">Presto</span></li>
198
+ <li><span class="font lobster">Roshe</span></li>
199
+ <li><span class="font prompt">Tempo</span></li>
200
+ <li><span class="font anton">Vomero</span></li>
201
+ <li><span class="font pt">Pegasus</span></li>
202
+ </ul>
203
+ </marquee-content>
204
+ </section>
205
+ <section class="data-code">
206
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-direction=&quot;auto&quot;</strong>
207
+ <p><code>data-mc-direction="auto"</code> &mdash; automatically changes the scrolling direction of the component when scrolling the page</p>
208
+ </section>
209
+ <section class="example-3">
210
+ <marquee-content
211
+ data-mc-clone="3"
212
+ data-mc-speed="60"
213
+ data-mc-direction="auto"
214
+ role="marquee">
215
+ <ul class="font lobster">
216
+ <li>Monarch</li>
217
+ <li>Benassi</li>
218
+ <li>Air Max</li>
219
+ <li>Cortez</li>
220
+ <li>Jordan</li>
221
+ <li>Presto</li>
222
+ <li>Roshe</li>
223
+ <li>Tempo</li>
224
+ <li>Vomero</li>
225
+ <li>Pegasus</li>
226
+ </ul>
227
+ </marquee-content>
228
+ </section>
229
+ <section class="data-code">
230
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-skew=&quot;-3&quot;</strong>
231
+ <p><code>data-mc-skew="-3"</code> &mdash; transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value)</p>
232
+ </section>
233
+ <section class="example-4">
234
+ <marquee-content
235
+ data-mc-clone="3"
236
+ data-mc-speed="60"
237
+ data-mc-skew="-3"
238
+ role="marquee">
239
+ <ul class="font pt">
240
+ <li>Monarch</li>
241
+ <li>Benassi</li>
242
+ <li>Air Max</li>
243
+ <li>Cortez</li>
244
+ <li>Jordan</li>
245
+ <li>Presto</li>
246
+ <li>Roshe</li>
247
+ <li>Tempo</li>
248
+ <li>Vomero</li>
249
+ <li>Pegasus</li>
250
+ </ul>
251
+ </marquee-content>
252
+ </section>
253
+ <section class="data-code">
254
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-min=&quot;1200&quot;</strong>
255
+ <p><code>data-mc-min="1200"</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>
256
+ </section>
257
+ <section class="example-5">
258
+ <marquee-content
259
+ data-mc-clone="3"
260
+ data-mc-speed="60"
261
+ data-mc-min="1200"
262
+ role="marquee">
263
+ <ul class="font pt">
264
+ <li>Monarch</li>
265
+ <li>Benassi</li>
266
+ <li>Air Max</li>
267
+ <li>Cortez</li>
268
+ <li>Jordan</li>
269
+ <li>Presto</li>
270
+ <li>Roshe</li>
271
+ <li>Tempo</li>
272
+ <li>Vomero</li>
273
+ <li>Pegasus</li>
274
+ </ul>
275
+ </marquee-content>
276
+ </section>
277
+ <section class="data-code">
278
+ <strong>data-mc-clone=&quot;3&quot; data-mc-speed=&quot;60&quot; data-mc-max=&quot;1200&quot;</strong>
279
+ <p><code>data-mc-max="1200"</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>
280
+ </section>
281
+ <section class="example-6">
66
282
  <marquee-content
67
- data-mc-min="1600"
68
- data-mc-clone="2"
69
- data-mc-speed="30"
70
- data-mc-skew="-2.4"
283
+ data-mc-clone="3"
284
+ data-mc-speed="60"
285
+ data-mc-max="1200"
71
286
  role="marquee">
72
- <ul class="logo-set">
73
- <li class="logo-set__item">
74
- 1
75
- </li>
76
- <li class="logo-set__item">
77
- 2
78
- </li>
79
- <li class="logo-set__item">
80
- 3
81
- </li>
82
- <li class="logo-set__item">
83
- 4
84
- </li>
85
- <li class="logo-set__item">
86
- 5
87
- </li>
88
- <li class="logo-set__item">
89
- 6
90
- </li>
91
- <li class="logo-set__item">
92
- 7
93
- </li>
287
+ <ul class="font pt">
288
+ <li>Monarch</li>
289
+ <li>Benassi</li>
290
+ <li>Air Max</li>
291
+ <li>Cortez</li>
292
+ <li>Jordan</li>
293
+ <li>Presto</li>
294
+ <li>Roshe</li>
295
+ <li>Tempo</li>
296
+ <li>Vomero</li>
297
+ <li>Pegasus</li>
94
298
  </ul>
95
299
  </marquee-content>
96
- </div>
300
+ </section>
97
301
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/gsap.min.js"></script>
98
302
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/ScrollTrigger.min.js"></script>
99
303
  <script src="js/marquee-content.min.js"></script>
@@ -2,18 +2,21 @@ export class MarqueeContent extends HTMLElement {
2
2
  constructor() {
3
3
  super()
4
4
 
5
+ this.mm = gsap.matchMedia()
6
+ this.tl = gsap.timeline()
5
7
  this.speed = this.dataset.mcSpeed || 20
6
8
  this.clone = this.dataset.mcClone
7
9
  this.skew = this.dataset.mcSkew
8
10
  this.abs = (this.skew < 0) ? this.skew * -1 : this.skew
9
11
  this.max = this.dataset.mcMax
10
12
  this.min = this.dataset.mcMin
11
- this.mm = gsap.matchMedia()
13
+ this.dir = this.dataset.mcDirection
12
14
 
13
15
  this.breakpoints()
14
16
  this.cloning()
15
17
  this.skewed()
16
- this.animate()
18
+ this.marquee()
19
+ this.reverse()
17
20
  }
18
21
 
19
22
  breakpoints() {
@@ -52,39 +55,70 @@ export class MarqueeContent extends HTMLElement {
52
55
  if(!this.skew) { return }
53
56
 
54
57
  this.mm.add(this.breakpoint, () => {
55
- gsap.set(this, {
56
- skewY: this.skew,
57
- 'transform-origin': 'center center',
58
- 'min-height': `calc(${this.abs * 1.25}vh + ${this.abs * 1.25}vw)`
59
- })
58
+ this.style.minHeight = `calc(${this.abs * 1.25}vh + ${this.abs * 1.25}vw)`
59
+ this.style.transformOrigin = `center center`
60
+ this.style.transform = `skew(0deg, ${this.skew}deg)`
61
+
62
+ return () => {
63
+ this.style.removeProperty('min-height')
64
+ this.style.removeProperty('transform-origin')
65
+ this.style.removeProperty('transform')
66
+ }
60
67
  })
61
68
  }
62
69
 
63
- animate() {
70
+ marquee() {
64
71
  this.mm.add(this.breakpoint, () => {
65
- gsap.defaults({
66
- overwrite: true
72
+ gsap.config({
73
+ nullTargetWarn: false
67
74
  })
68
75
 
76
+ this.tl.paused(true)
77
+
69
78
  gsap.set(this.children, {
70
79
  'will-change': 'transform'
71
80
  })
72
81
 
73
- let animate = gsap.to(this.children, {
82
+ this.tl.to(this.children, {
74
83
  duration: this.speed,
75
84
  x: '-100%',
76
85
  ease: 'none',
77
- repeat: -1,
78
- scrollTrigger: {
79
- trigger: this,
80
- toggleActions: 'play pause play pause',
81
- start: '-=50% bottom',
82
- end: 'bottom top',
83
- onUpdate: ({ direction }) => {
84
- ( direction === 1 ) ? animate.timeScale(1) : animate.timeScale(-1)
85
- }
86
+ repeat: -1
87
+ }).timeScale(this.dir === 'ltr' ? -1 : 1).totalProgress(.5)
88
+
89
+ ScrollTrigger.create({
90
+ trigger: this,
91
+ start: 'top bottom',
92
+ end: 'bottom top',
93
+ onEnter: () => this.tl.resume(),
94
+ onLeave: () => this.tl.pause(),
95
+ onEnterBack: () => this.tl.resume(),
96
+ onLeaveBack: () => this.tl.pause()
97
+ })
98
+ })
99
+ }
100
+
101
+ reverse() {
102
+ if(this.dir !== 'auto') { return }
103
+
104
+ this.mm.add(this.breakpoint, () => {
105
+ let currentScroll = 0,
106
+ scrollDirection = 1
107
+
108
+ window.addEventListener('scroll', () => {
109
+ let orientation = (window.pageYOffset > currentScroll) ? 1 : -1
110
+
111
+ if (orientation !== scrollDirection) {
112
+ gsap.to(this.tl, {
113
+ timeScale: orientation,
114
+ overwrite: true
115
+ })
116
+
117
+ scrollDirection = orientation
86
118
  }
87
- }).timeScale(1).totalProgress(.5)
119
+
120
+ currentScroll = window.pageYOffset
121
+ })
88
122
  })
89
123
  }
90
124
  }