Advertisement
1xptolevitico69

CreateElement ( audio ). Animation onclick. Audio ontimeupda

Jan 5th, 2020
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9. .bt {
  10. box-sizing:border-box;
  11. width:180px;
  12. height:180px;
  13. border-radius:50%;
  14. outline:none;
  15. background-color:red;
  16. color:white;
  17. font-size:30px;
  18. font-family:arial;
  19. font-weight:900;
  20. border:20px solid white;
  21. cursor:pointer;
  22. }
  23.  
  24. .bt_container {
  25. border:1px solid;
  26. width:180px;
  27. height:180px;
  28. border-radius:50%;
  29. display:block;
  30. position:absolute;
  31. top:50%;
  32. left:50%;
  33. transform:translate(-50%,-50%);
  34. }
  35.  
  36. #box {
  37. width:60%;
  38. position:absolute;
  39. top:30%;
  40. left:50%;
  41. transform:translate(-50%,-30%);
  42. }
  43.  
  44. audio {
  45. width:100%;
  46. position:absolute;
  47. outline:none;
  48. background-color:rgba(128,128,128,0.1);
  49. }
  50.  
  51. img {
  52. width:100%;
  53. display:block;
  54. }
  55.  
  56. #outer {
  57. z-index:-1;
  58. border:20px solid white;
  59. width:140px;
  60. height:140px;
  61. border-radius:50%;
  62. display:inline-block;
  63. position:absolute;
  64. top:0;
  65. left:0;
  66. background-color:red;
  67. cursor:pointer;
  68. }
  69.  
  70. .sp {
  71. border:10px solid white;
  72. display:inline-block;
  73. margin:20px;
  74. border-radius:50%;
  75. }
  76.  
  77. @keyframes jolie {
  78. 100% {    transform:rotate(360deg);        }
  79. }
  80.  
  81.  
  82. </style>
  83. </head>
  84. <body>
  85.  
  86.  
  87.  
  88.  
  89. <div id='box'>
  90. <img id='image' src='https://neanderthal-emergen.000webhostapp.com/image.png'/>
  91. <span class='bt_container'>
  92. <button class='bt' onclick='play()'>Play</button>
  93. <span onclick='stop()' id='outer'><span class='sp'></span></span>
  94. </span>
  95. </div>
  96.  
  97.  
  98.  
  99.  
  100.  
  101. <script>
  102. i=1;
  103.  
  104. audio=document.createElement('audio');
  105. box.appendChild(audio);
  106.  
  107. function play(){
  108.  
  109.       x = setInterval(function(){
  110.        i++;
  111.           },1000);
  112.  
  113. audio.src='https://neanderthal-emergen.000webhostapp.com/Bossa Nova.mp3';
  114. audio.controls=true;
  115. audio.play();
  116. audio.currentTime=i;
  117. outer.style.zIndex='1';
  118. outer.style.animation='jolie 6s linear infinite';
  119. audio.ontimeupdate=function(){
  120. i=audio.currentTime;
  121. if(audio.currentTime >= audio.duration){
  122. outer.style.zIndex='-1';
  123. outer.style.animation='';
  124. audio.controls=false;
  125. clearInterval(x);
  126. i=1;
  127. }
  128. }
  129. }
  130.  
  131. function stop(){
  132. audio.pause();
  133. clearInterval(x);
  134. audio.currentTime=i;
  135. outer.style.zIndex='-1';
  136. outer.style.animation='';
  137. }
  138.  
  139.  
  140. </script>
  141. </body>
  142. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement