Advertisement
1xptolevitico69

Audio loop onclick + Toggle button

Jun 6th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8. div{width:400px;height:600px;display:block;margin:auto;  }
  9. img{width:400px;position:absolute;}
  10. audio{width:0;}
  11. button{ padding:20px;border-radius:50%;background-color:red;
  12. position:absolute;outline:none;transform:translate(350px,10px);}
  13. </style>
  14. </head>
  15. <body>
  16.  
  17. <div>
  18. <img src='drake.jpg'/>
  19. <audio id='audio' controls loop>
  20.  <source src='Drake.mp3' type='audio/mp3'>
  21.  </audio>
  22. <button id='bt'></button>
  23. </div>
  24.  
  25.  
  26. <!--   YOUTUBE LINK ( https://youtu.be/007lWkD5NSE ) Drake - NonStop (Official Song)  -->
  27.  
  28.  
  29. <script>
  30.  
  31. i=0;
  32. bt.onclick=()=>{
  33. if(i==0){
  34. audio.play();
  35. bt.style.backgroundColor='darkgreen';
  36. i=1;
  37. }else if(i==1){
  38. audio.pause();
  39. bt.style.backgroundColor='red';
  40. i=0;
  41. }
  42. }
  43.  
  44. </script>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement