Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style>
- div.IDiv
- {
- background-image:url('immagine.png');
- width:300px;
- height:300px;
- margin:auto 0;
- }
- </style>
- <script type="text/javascript">
- function generaDiv()
- {
- var contenitore=document.getElementById("contenitore");
- var ImgDiv=document.createElement("div");
- ImgDiv.className="IDiv";
- var DivButton=document.createElement("div");
- var ButtDiv=document.createElement("button");
- ButtDiv.innerText="Chiudi";
- DivButton.appendChild(ButtDiv);
- ImgDiv.appendChild(DivButton);
- ButtDiv.onclick=function()
- {
- contenitore.removeChild(ImgDiv);
- }
- var su=Math.floor(Math.random() * 100) + 1;
- var sinistra=Math.floor(Math.random() * 100) + 1;
- ImgDiv.style.position="absolute";
- ImgDiv.style.left=sinistra+"%";
- ImgDiv.style.top=su+"%";
- contenitore.appendChild(ImgDiv);
- }
- </script>
- </head>
- <body>
- <div>
- <button onclick="generaDiv();">Genera Foto </button>
- </div>
- <div id="contenitore"> </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement