Advertisement
Ziad1569845

Untitled

Jun 26th, 2023
1,102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.57 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Ziadod</title>
  5.     <style>
  6.         body {
  7.             background-color: #aaaaaa;
  8.             text-align: center;
  9.             margin: 0;
  10.             padding: 0;
  11.         }
  12.         h1 {
  13.             position: absolute;
  14.             top: 0;
  15.             left: 50%;
  16.             transform: translate(-50%, 10%);
  17.         }
  18.         button {
  19.             font-size: 24px;
  20.             border-radius: 10px;
  21.             box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
  22.             padding: 20px 40px;
  23.             background-color: #838383;
  24.             color: #000000;
  25.             position: absolute;
  26.             top: 50%;
  27.             left: 50%;
  28.             transform: translate(-50%, -50%);
  29.             margin-top: 20px;
  30.             max-width: 80%;
  31.         }
  32.         .image {
  33.             position: absolute;
  34.             top: 50%;
  35.             left: 50%;
  36.             transform: translate(-50%, -50%);
  37.             display: none;
  38.             opacity: 0;
  39.             transition: opacity 0.5s;
  40.         }
  41.     </style>
  42.     <script>
  43.         function showImage(image) {
  44.             image.style.width = '200px';
  45.             image.style.display = 'block';
  46.             setTimeout(function() {
  47.                 image.style.opacity = '1';
  48.             }, 0);
  49.             setTimeout(function() {
  50.                 image.style.opacity = '0';
  51.             }, 500);
  52.         }
  53.        
  54.         function playSound(sound) {
  55.            var audio = new Audio(sound);
  56.            audio.play();
  57.            audio.addEventListener('ended', function() {
  58.       if (sound === 'Sound-1.mp3') {
  59.       showImage(document.getElementById('image-1'));
  60.     } else if (sound === 'Sound-2.mp3') {
  61.         showImage(document.getElementById('image-2'));
  62.     }
  63.   });
  64. }
  65.        
  66.         document.addEventListener('DOMContentLoaded', function() {
  67.             var button = document.querySelector('button');
  68.             button.addEventListener('click', function() {
  69.                 playSound('Sound-1.mp3');
  70.                 var x = Math.floor(Math.random() * (window.innerWidth - button.offsetWidth - 20));
  71.                 var y = Math.floor(Math.random() * (window.innerHeight - button.offsetHeight - 20));
  72.                 button.style.left = x + 'px';
  73.                 button.style.top = y + 'px';
  74.             });
  75.         });
  76.     </script>
  77. </head>
  78. <body>
  79.     <h1>a litile ball</h1>
  80.     <button>Click me!</button>
  81.     <img id="image-1" class="image" src="MiddleImage-1.gif" alt="image-1">
  82.     <img id="image-2" class="image" src="MiddleImage-2.gif" alt="image-2">
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement