-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.html
60 lines (46 loc) · 1 KB
/
template.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<html>
<head>
<title>Custom Element simples</title>
</head>
<body>
<h3>Custom element simples</h3>
<custom-element>
<h3>custom element 01 - aberto</h3>
</custom-element>
<custom-element>
<h3>custom element 02 - aberto</h3>
</custom-element>
<custom-element>
<h3>custom element 03 - aberto</h3>
</custom-element>
<custom-element>
<h3>custom element 04 - aberto</h3>
</custom-element>
<template id="myFirstWebcomponent">
<style>
h3{
color: #ff9100;
font-size: 2rem;
}
</style>
<h3>Hello world!</h3>
<slot></slot>
</template>
<script>
class CustomElementClass extends HTMLElement
{
constructor()
{
super();
const template = document.getElementById('myFirstWebcomponent');
let shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(template.content.cloneNode(true));
}
}
if(!'customElements' in window) {
console.error( new Error('Seu browser não suporta a customElements') );
}
customElements.define('custom-element', CustomElementClass);
</script>
</body>
</html>