A Collection of useful frontend snippets;
Last active
March 26, 2022 16:49
-
-
Save shawn-sandy/bc31f2ab3180aa190babdfee999f178e to your computer and use it in GitHub Desktop.
Frontend Snippets
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
<!-- @format --> | |
<style> | |
dialog { | |
--diag-bg: whitesmoke; | |
--diag-bg-img: none; | |
--diag-x: 1.5rem; | |
--diag-y: 1.5rem; | |
--bk-drop: rgba(0, 0, 0, 0.5); | |
background-color: var(--diag-bg); | |
background-image: var(--diag-bg-img); | |
padding-inline: var(--diag-x); | |
padding-block: var(--diag-y); | |
} | |
dialog::backdrop { | |
--bk-drop: rgba(0, 0, 0, 0.5); | |
background-color: var(--bk-drop); | |
} | |
</style> | |
<div> | |
<button type="button" onclick="openDialog('#dialog-elm',this)"> | |
Open Dialog | |
</button> | |
<dialog id="dialog-elm"> | |
<h3>Example modal</h3> | |
<p> | |
Native HTML5 Modals (Dialogs) are finally here and available across all | |
ever green browsers and they are fun! | |
</p> | |
<button class="btn btn-close" onclick="closeDialog(this)">Close</button> | |
</dialog> | |
</div> | |
<script> | |
function openDialog(target, elm) { | |
console.log(target, elm) | |
document.querySelector(target).showModal() | |
} | |
function closeDialog(elm) { | |
elm.closest('dialog').close() | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment