Advertisement
Ziad1569845

Untitled

Jun 26th, 2023
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.42 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.         var sounds = ['Sound-1.mp3', 'Sound-2.mp3'];
  44.         var soundIndex = 0;
  45.        
  46.         function showImage() {
  47.             var image = document.getElementById('image');
  48.             image.style.width = '200px';
  49.             image.style.display = 'block';
  50.             setTimeout(function() {
  51.                 image.style.opacity = '1';
  52.             }, 0);
  53.             setTimeout(function() {
  54.                 image.style.opacity = '0';
  55.             }, 500);
  56.         }
  57.        
  58.         function playSound() {
  59.             var audio = new Audio(sounds[soundIndex]);
  60.             if (soundIndex == 1) {
  61.                 audio.volume = 0.5;
  62.             }
  63.             audio.play();
  64.             soundIndex++;
  65.             if (soundIndex > 1) {
  66.                 soundIndex = 0;
  67.             }
  68.             var button = document.querySelector('button');
  69.             var x = Math.floor(Math.random() * (window.innerWidth - button.offsetWidth - 20));
  70.             var y = Math.floor(Math.random() * (window.innerHeight - button.offsetHeight - 20));
  71.             button.style.left = x + 'px';
  72.             button.style.top = y + 'px';
  73.             showImage();
  74.         }
  75.     </script>
  76. </head>
  77. <body>
  78.     <h1>a litile ball</h1>
  79.     <button onclick="playSound()">Click me!</button>
  80.     <img id="image" src="MiddleImage.gif" alt="image" style="display:none;">
  81. </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement