Advertisement
1xptolevitico69

Prevent second click with ( preventDefault )

Jul 16th, 2022
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <link rel="shortcut icon" href="https://1xpto.netlify.app/items/favicon.gif" type="image/x-icon">
  5.   <link rel="name" href="https://www.facebook.com/ManuelJSAndrade/">
  6.   <link rel="name" href="https://www.instagram.com/jolie1xpto/">
  7.   <link rel="tag" href="https://1xpto.netlify.app/articles/html/Prevent second click with ( preventDefault )">
  8.   <meta charset="UTF-8">
  9.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  10.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11.   <title>Prevent second click with ( preventDefault )</title>
  12.   <style>
  13.  
  14.  
  15.     body {
  16.       cursor: context-menu;
  17.       margin: 0;
  18.       font-family: calibri;
  19.       overflow-x: hidden;
  20.     }
  21.  
  22.     button {
  23.       border: none;
  24.       outline: none;
  25.       background-color: red;
  26.       color: white;
  27.     }
  28.  
  29.     textarea {
  30.       border: none;
  31.       background-color: white;
  32.       resize: none;
  33.       outline: none;
  34.     }
  35.  
  36.     a {
  37.       text-decoration: none;
  38.     }
  39.  
  40.     audio {
  41.       background-color: rgba(128, 128, 128, 0.1);
  42.     }
  43.  
  44.              /*  ------------  default  ---------------   */
  45.  
  46.  
  47.     #txt {
  48.       font-size: 5vw;text-align:center;
  49.     }
  50.  
  51.  
  52.     #btn {
  53.       margin: 10px;
  54.       padding: 5px 20px;
  55.     }
  56.  
  57.  
  58.  
  59.     @media all and (orientation:portrait) and (max-width:425px) {
  60.       #txt {
  61.         font-size: 15vw;
  62.       }
  63.     }
  64.  
  65.     @media all and (orientation:landscape) and (max-width:538px) {
  66.       #txt {
  67.         font-size: 10vw;
  68.       }
  69.     }
  70.  
  71.     @media all and (orientation:landscape) and (min-width:539px) and (max-width:768px) {
  72.       #txt {
  73.         font-size: 8vw;
  74.       }
  75.     }
  76.   </style>
  77. </head>
  78.  
  79. <body>
  80.  
  81.   <center><button id='btn'>Prevent second click with ( preventDefault )</button></center>
  82.   <h1 id='txt'></h1>
  83.  
  84.  
  85.  
  86.   <script>
  87.     i = 0;
  88.     def = true;
  89.  
  90.     btn.addEventListener('click', function() {
  91.       if (def) {
  92.         foo();
  93.         def = false;
  94.       } else {
  95.         event.preventDefault();
  96.       }
  97.     });
  98.  
  99.     (foo = () => {
  100.       setInterval(() => {
  101.         txt.innerHTML = i;
  102.         i++;
  103.       }, 500);
  104.     })
  105.  
  106.   </script>
  107. </body>
  108. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement