joicomponents
Version:
Design patterns to build native web components
34 lines (31 loc) • 898 B
HTML
<!--<script src="polyfill-loader.js"></script>-->
<script src="polyfill-loader.js" defer></script>
<script type="module">
window.polyfill.ready(() => {
class MyElement extends HTMLElement {
connectedCallback() {
this.style.display = "block";
this.style.width = "20px";
this.style.height = "25px";
this.style.borderRadius = "50%";
this.style.backgroundColor = "orange";
}
}
console.log("customElements.define");
customElements.define("my-element", MyElement);
});
setTimeout(
() => {
let me = document.createElement("my-element");
document.body.appendChild(me);
me.style.border = "2px dotted red";
},
1000
);
setTimeout(
() => document.body.innerHTML += "<my-element></my-element>",
2000
);
</script>
<script>console.log("adding my-element"); </script>
<my-element></my-element>