- 画面の左上に通知を5秒だけ出す、いわゆるtoastの単純な実装です。
-
-
Save hyuki/ba77f290fbb42f2877ede03dab2bf0ac to your computer and use it in GitHub Desktop.
toast-it - Simplest toast.
This file contains hidden or 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
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>toast-it</title> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1.1.2/new.min.css"> | |
| </head> | |
| <body> | |
| <button type="button" id="TOAST-BUTTON" href="#">showToast</button> | |
| <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> | |
| <script src="toast-it.js"></script> | |
| <script> | |
| $(function() { | |
| $('#TOAST-BUTTON').click(function() { | |
| showToast('HELLO!'); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| // toast-it.js | |
| function initToast() { | |
| const e = `<div id="TOAST-IT">TOAST-IT</div>`; | |
| const o = $(e); | |
| o.prependTo('body'); | |
| o.css("position", "fixed"); | |
| o.css("z-index", "5000"); | |
| o.css("top", "0px"); | |
| o.css("left", "0px"); | |
| o.css("padding", "10px"); | |
| o.css("margin", "10px"); | |
| o.css("border-radius", "5px"); | |
| o.css("display", "none"); | |
| o.css("color", "white"); | |
| o.css("background-color", "#1976D2"); | |
| } | |
| function showToast(s) { | |
| $('#TOAST-IT').text(s); | |
| $('#TOAST-IT').show(); | |
| setTimeout(function() { | |
| $('#TOAST-IT').hide(); | |
| }, 5000); | |
| } | |
| initToast(); | |
Author
hyuki
commented
Feb 20, 2022

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