在網頁中讓div飄起來
阿新 • • 發佈:2019-02-18
宣告:以下程式碼在FIreFox中無法正常執行
<html> <head> <title></title> </head> <script language="javascript"> function a() { document.getElementById("b").style.pixelTop=document.body.scrollTop; } function v(){ document.getElementById("b").style.display="none"; } var a=1; var b=1; function aa(){ var w=document.getElementById("d"); if(w.style.pixelLeft>400){ a=-1; } if(w.style.pixelLeft<0){ a=1; } if(w.style.pixelTop>400){ b=-1; } if(w.style.pixelTop<0){ b=1; } w.style.pixelTop=w.style.pixelTop+b; w.style.pixelLeft=w.style.pixelLeft+a; } setInterval("aa()", 5); var l=1; var v=1; function cc(){ var w=document.getElementById("b"); if(w.style.pixelLeft>400){ l=-1; } if(w.style.pixelLeft<0){ l=1; } if(w.style.pixelTop>400){ v=-1; } if(w.style.pixelTop<0){ v=1; } w.style.pixelTop=w.style.pixelTop+v; w.style.pixelLeft=w.style.pixelLeft+l; } setInterval("cc()",59); </script> <body onscroll="a()"> <div id="b" style="position:absolute;top:0px;left:0px" > <p><img src="file:///J:/按鈕圖示/24.jpg" width="128" height="128"><span onclick="v()">x</span></p><br> </div> <div id="d" style="position:absolute;top:100px;left:150px"><img src="file:///J:/按鈕圖示/21.jpg" width="128" height="128"> </div> <img src="f.JPG" width="1024" height="768"> </body> </html>