Last active
April 4, 2021 01:22
-
-
Save jremi/5aff472f1556fcf9dc0fefb96eb9b908 to your computer and use it in GitHub Desktop.
mini element selector plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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