Skip to content

Instantly share code, notes, and snippets.

@danny-andrews
Last active March 1, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danny-andrews/dc1a829e9a0705b637607d77bed2f952 to your computer and use it in GitHub Desktop.
Save danny-andrews/dc1a829e9a0705b637607d77bed2f952 to your computer and use it in GitHub Desktop.
Vanilla Ticker
const template = document
.createElement("template");
template.innerHTML = `<span></span>`;
class MyTicker extends HTMLElement {
constructor() {
super();
this.ticks = 0;
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(
template.content.cloneNode(true)
);
this.spanValue = shadowRoot
.querySelector("span");
}
update() {
this.spanValue.innerText = this.ticks;
}
tick() {
setTimeout(() => {
this.ticks += 1;
this.update();
this.tick();
}, 1000);
}
connectedCallback() {
this.update();
this.tick();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment