Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. div.IDiv
  5. {
  6. background-image:url('immagine.png');
  7. width:300px;
  8. height:300px;
  9. margin:auto 0;
  10. }
  11.  
  12.  
  13.  
  14.  
  15. </style>
  16.  
  17.  
  18. <script type="text/javascript">
  19. function generaDiv()
  20. {
  21. var contenitore=document.getElementById("contenitore");
  22. var ImgDiv=document.createElement("div");
  23. ImgDiv.className="IDiv";
  24. var DivButton=document.createElement("div");
  25. var ButtDiv=document.createElement("button");
  26.  
  27.  
  28.  
  29. ButtDiv.innerText="Chiudi";
  30.  
  31. DivButton.appendChild(ButtDiv);
  32.  
  33. ImgDiv.appendChild(DivButton);
  34.  
  35. ButtDiv.onclick=function()
  36. {
  37. contenitore.removeChild(ImgDiv);
  38. }
  39.  
  40. var su=Math.floor(Math.random() * 100) + 1;
  41. var sinistra=Math.floor(Math.random() * 100) + 1;
  42.  
  43. ImgDiv.style.position="absolute";
  44. ImgDiv.style.left=sinistra+"%";
  45. ImgDiv.style.top=su+"%";
  46.  
  47.  
  48. contenitore.appendChild(ImgDiv);
  49.  
  50.  
  51.  
  52. }
  53.  
  54. </script>
  55. </head>
  56.  
  57. <body>
  58. <div>
  59. <button onclick="generaDiv();">Genera Foto </button>
  60. </div>
  61.  
  62. <div id="contenitore"> </div>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement