File tree Expand file tree Collapse file tree 3 files changed +66
-30
lines changed Expand file tree Collapse file tree 3 files changed +66
-30
lines changed Original file line number Diff line number Diff line change 5
5
< title > custom-element demo</ title >
6
6
</ head >
7
7
< body >
8
- < custom-element > </ custom-element >
8
+ < marquee-text duration =" 1s " > < p > Hello World This is 24 Web Components </ p > </ marquee-text >
9
9
10
10
< script type ="module ">
11
11
// import 'https://unpkg.com/@github/custom-element-boilerplate@latest/dist/custom-element.js'
12
- import '../src/custom -element.ts'
12
+ import '../src/marquee-text -element.ts'
13
13
</ script >
14
14
</ body >
15
15
</ html >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ class MarqueeTextElement extends HTMLElement {
2
+ static observedAttributes = [ 'duration' ]
3
+
4
+
5
+ #renderRoot = this . attachShadow ( { mode : 'open' } )
6
+
7
+ get duration ( ) {
8
+ const value = this . getAttribute ( 'duration' )
9
+ return value
10
+ }
11
+
12
+ set duration ( value : string ) {
13
+ this . setAttribute ( 'duration' , value )
14
+ }
15
+
16
+ attributeChangedCallback ( name : 'duration' , oldValue : null | string , newValue : null | string ) {
17
+ if ( oldValue === newValue ) return
18
+ if ( newValue === null ) return
19
+ if ( newValue ) this . style . setProperty ( '--animation-duration' , newValue )
20
+ }
21
+
22
+ connectedCallback ( ) : void {
23
+ this . #renderRoot. innerHTML = `
24
+ <style>
25
+ @keyframes marqueeeee {
26
+ 0% {
27
+ translate: -100%;
28
+ }
29
+ 100% {
30
+ translate: 100vw;
31
+ }
32
+ }
33
+ :host slot {
34
+ animation: var(--animation-duration, 5s) linear infinite marqueeeee;
35
+ display: inline-block;
36
+ }
37
+ :host {
38
+ overflow: hidden;
39
+ max-width: 100vw;
40
+ display: block;
41
+ }
42
+ @media (prefers-reduced-motion) {
43
+ :host slot {
44
+ animation: none;
45
+ }
46
+ }
47
+ </style>
48
+ <slot></slot>
49
+ `
50
+ }
51
+ }
52
+
53
+ declare global {
54
+ interface Window {
55
+ MarqueeTextElement : typeof MarqueeTextElement
56
+ }
57
+ }
58
+
59
+ export default MarqueeTextElement
60
+
61
+ if ( ! window . customElements . get ( 'marquee-text' ) ) {
62
+ window . MarqueeTextElement = MarqueeTextElement
63
+ window . customElements . define ( 'marquee-text' , MarqueeTextElement )
64
+ }
You can’t perform that action at this time.
0 commit comments