Skip to content

Instantly share code, notes, and snippets.

@jremi
Last active April 4, 2021 01:22
Show Gist options
  • Save jremi/5aff472f1556fcf9dc0fefb96eb9b908 to your computer and use it in GitHub Desktop.
Save jremi/5aff472f1556fcf9dc0fefb96eb9b908 to your computer and use it in GitHub Desktop.
mini element selector plugin
const myPlugin = function(domSelector) {
const el = document.querySelector(domSelector);
return {
text(text) {
el.innerText = text;
return this;
},
color(color) {
el.style.color = color;
return this;
},
background(color) {
el.style.backgroundColor = color;
return this;
},
wait(ms) {
return new Promise(resolve => {
setTimeout(() => resolve(this), ms);
});
}
};
};
let max = 10;
(async el => {
for (let x = 0; x < max; x++) {
await el
.text("Hello World!")
.color("green")
.wait(2000);
await el.background("yellow").wait(4000);
await el.color("pink").wait(1000);
await el.background("orange");
}
})(myPlugin("#app"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment