Guest User

Untitled

a guest
Dec 20th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.81 KB | None | 0 0
  1. <dialog id="ref-dialog">
  2.   <div id="ref-dialog-content"></div>
  3.   <form method="dialog">
  4.     <button autofocus>닫기</button>
  5.   </form>
  6. </dialog>
  7.  
  8. <style>
  9. #ref-dialog {
  10.   max-width: calc(100% - 2rem);
  11. }
  12. #ref-dialog::backdrop {
  13.   background-color: rgba(0, 0, 0, 0.5);
  14. }
  15. #ref-dialog > button {
  16.   width: calc(100% + 1em);
  17.   margin: 1em -0.5em -0.5em -0.5em;
  18.   padding: 0.5em;
  19. }
  20. </style>
  21.  
  22. <script>
  23. document.querySelectorAll('a[href^="#ref"]')
  24.   .forEach(el => el.addEventListener('click', e => {
  25.     e.preventDefault()
  26.     const dialog = document.getElementById('ref-dialog')
  27.     const dialogContent = document.getElementById('ref-dialog-content')
  28.     dialogContent.innerHTML = document.getElementById(new URL(el.href).hash.slice(1)).innerHTML
  29.     if(!dialog.open)
  30.       dialog.showModal()
  31.   }))
  32. </script>
Add Comment
Please, Sign In to add comment