-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmar-quee.js
44 lines (43 loc) · 1.58 KB
/
mar-quee.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
customElements.define('mar-quee',
class extends HTMLElement {
constructor() {
super();
// let template = document.getElementById('mar-quee');
let template = document.createElement('template');
// CSS taken from: https://stackoverflow.com/a/44805879
template.innerHTML = `
<style>
.marquee {
position: relative;
display: inline-block;
overflow: hidden;
height: var(--marquee-height, 25px);
width: var(--marquee-width, 100px);
}
.marquee span {
position: absolute;
margin: 0;
line-height: var(--marquee-height, 25px);
white-space: nowrap;
animation: marquee;
animation-timing-function: var(--marquee-animation-timing-function, linear);
animation-duration: var(--marquee-animation-duration, 3s);
animation-iteration-count: var(--marquee-animation-iteration-count, infinite);
}
@keyframes marquee {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}
</style>
<div class="marquee">
<span>
${this.innerHTML || "EXAMPLE TEXT"}
</span>
</div>
`;
let templateContent = template.content;
console.log(this.innerHTML)
const shadowRoot = this.attachShadow({mode: 'open'})
.appendChild(templateContent.cloneNode(true));
}
})