Skip to content

Instantly share code, notes, and snippets.

@eric1iu
eric1iu / star-wars-planets.html
Created October 19, 2022 00:07 — forked from richard-flosi/star-wars-planets.html
Web Component using Custom Element, Shadow DOM, fetch, async/await, and the Star Wars API
<html>
<head>
<script>
customElements.define("star-wars-planets", class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
static get observedAttributes() { return ["loading", "planets"]; }
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}
@eric1iu
eric1iu / isElementInViewport.js
Created April 18, 2018 17:01 — forked from davidtheclark/isElementInViewport.js
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@eric1iu
eric1iu / _.md
Created November 15, 2013 01:37
Tributary inlet
@eric1iu
eric1iu / _.md
Created November 4, 2013 02:43
workload