Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="shortcut icon" href="https://1xpto.netlify.app/items/favicon.gif" type="image/x-icon">
- <link rel="name" href="https://www.facebook.com/ManuelJSAndrade/">
- <link rel="name" href="https://www.instagram.com/jolie1xpto/">
- <link rel="tag" href="https://1xpto.netlify.app/articles/html/Prevent second click with ( preventDefault )">
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Prevent second click with ( preventDefault )</title>
- <style>
- body {
- cursor: context-menu;
- margin: 0;
- font-family: calibri;
- overflow-x: hidden;
- }
- button {
- border: none;
- outline: none;
- background-color: red;
- color: white;
- }
- textarea {
- border: none;
- background-color: white;
- resize: none;
- outline: none;
- }
- a {
- text-decoration: none;
- }
- audio {
- background-color: rgba(128, 128, 128, 0.1);
- }
- /* ------------ default --------------- */
- #txt {
- font-size: 5vw;text-align:center;
- }
- #btn {
- margin: 10px;
- padding: 5px 20px;
- }
- @media all and (orientation:portrait) and (max-width:425px) {
- #txt {
- font-size: 15vw;
- }
- }
- @media all and (orientation:landscape) and (max-width:538px) {
- #txt {
- font-size: 10vw;
- }
- }
- @media all and (orientation:landscape) and (min-width:539px) and (max-width:768px) {
- #txt {
- font-size: 8vw;
- }
- }
- </style>
- </head>
- <body>
- <center><button id='btn'>Prevent second click with ( preventDefault )</button></center>
- <h1 id='txt'></h1>
- <script>
- i = 0;
- def = true;
- btn.addEventListener('click', function() {
- if (def) {
- foo();
- def = false;
- } else {
- event.preventDefault();
- }
- });
- (foo = () => {
- setInterval(() => {
- txt.innerHTML = i;
- i++;
- }, 500);
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement