Skip to content

Instantly share code, notes, and snippets.

@shimondoodkin
Created October 13, 2021 15: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 shimondoodkin/274b1e7ecd5ad13095a4db706e621c05 to your computer and use it in GitHub Desktop.
Save shimondoodkin/274b1e7ecd5ad13095a4db706e621c05 to your computer and use it in GitHub Desktop.
tiny vanilla JavaScript toast notification
var toast_top=8;
function toast(text,timeoutMs)
{
let atoast = document.createElement('div');
with(atoast.style) {
backgroundColor='#fef7e6'; border='1px solid #f0ac00';
boxShadow='5px 10px #888888'; color='#000000'; padding='8px';
left="50%"; width='-50%'; top=toast_top+'px'; display='block'; position='fixed';
zIndex=10000; }
atoast.innerText=text;
document.body.appendChild(atoast);
let height=atoast.offsetHeight; toast_top+=height;
setTimeout(()=>{ document.body.removeChild(atoast); toast_top-=height; },timeoutMs);
}
toast("hello",1500)
setTimeout( ()=>{
toast("hello",1500)
},500)
@shimondoodkin
Copy link
Author

shimondoodkin commented Oct 13, 2021

JavaScript notification popup with no dependencies, like a one-liner.

copy paste into the console to see it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment