Advertisement
1xptolevitico69

Audio animation bars ( Javascript )

Jan 5th, 2022
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.83 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Audio animation bars ( Javascript )</title>
  9.   <style>
  10.  
  11.     .clone {
  12.       position: absolute;
  13.       top: 10px;
  14.       left: 10px;
  15.       text-decoration: none;
  16.       background-color: red;
  17.       width: 150px;
  18.       text-align: center;
  19.       color: snow;
  20.       font-family: arial black;
  21.       padding: 5px 20px;
  22.     }
  23.  
  24.     div {
  25.       display: none;
  26.       height: 1px;
  27.       width: 5px;
  28.       position: relative;
  29.       transform-origin: left top;
  30.     }
  31.  
  32.     container {
  33.       position: relative;
  34.       width: 600px;
  35.       margin: 100px auto;
  36.       display: block;
  37.     }
  38.  
  39.     box {
  40.       position: absolute;
  41.       left: 0;
  42.       bottom: -14px;
  43.       width: 50px;
  44.       transform: rotateX(180deg);
  45.     }
  46.  
  47.     audio {
  48.       position: absolute;
  49.       left: 50px;
  50.       bottom: 0px;
  51.       border: 1px solid red;
  52.       outline: none;
  53.       height: 30px;
  54.       background-color: rgba(128, 128, 128, 0.1);
  55.     }
  56.  
  57.     span {
  58.       position: absolute;
  59.       left: 370px;
  60.       top: -30px;
  61.       font-size: 20px;
  62.       font-family: arial black;
  63.     }
  64.   </style>
  65. </head>
  66.  
  67. <body>
  68.   <container>
  69.     <box>
  70.       <div style='background-color:navy'></div>
  71.       <div style='background-color:green'></div>
  72.       <div style='background-color:orange'></div>
  73.       <div style='background-color:red'></div>
  74.       <div style='background-color:maroon'></div>
  75.     </box>
  76.     <audio id='audio' src='https://1xpto.netlify.app/audio/audio2.mp3' controls></audio>
  77.     <span id='sp'>Status OFF</span>
  78.   </container>
  79.  
  80.   <a class='clone' title="Subscribe and hit the notification bell for more updates. It's free." href='https://www.youtube.com/channel/UCqLpDK0eOsG1eEeF9jOUZkw'>SUBSCRIBE</a>
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.   <script>
  88.     foo = document.getElementsByTagName('div');
  89.     a = 0;
  90.     audio.onplay = function() {
  91.       for (i = 0; i < foo.length; i++) {
  92.        foo[i].style.display = 'inline-block';
  93.        audio.play();
  94.         sp.innerHTML='Status ON';
  95.      }
  96.    }
  97.    audio.onended = () => {
  98.       for (i = 0; i < foo.length; i++) {
  99.        foo[i].style.display = 'none';
  100.         sp.innerHTML='Status OFF';
  101.      }
  102.    }
  103.    audio.ontimeupdate = () => {
  104.       if (audio.paused) {
  105.         for (i = 0; i < foo.length; i++) {
  106.          foo[i].style.display = 'none';
  107.         sp.innerHTML='Status OFF';
  108.        }
  109.      }
  110.    }
  111.  
  112.    function f() {
  113.      setInterval(() => {
  114.         var x = Math.floor((Math.random() * 40) + 1);
  115.         foo[a].style.transform = 'scaleY(' + x + ')';
  116.         a++;
  117.         if (a == foo.length) {
  118.           a = 0;
  119.         }
  120.       }, 100);
  121.     }
  122.     f();
  123.   </script>
  124.  
  125. </body>
  126.  
  127. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement