网上看到许多让图片跟随鼠标移动,感觉代码很复杂,还不兼容,其实可以很简单的实现:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>图片跟随鼠标</title> </head> <body> <script type="text/javascript"> function doMouseMove(e) { var evt = e||window.event; var x = evt.clentX || evt.x; var y = evt.clentY || evt.y; layerName = ‘iit‘; var curElement=document.getElementById("myImg"); curElement.style.left=x+"px"; curElement.style.top=y+"px"; } document.onmousemove = doMouseMove; </script> <div ID="myDiv"> <img id="myImg" src="img/a2.jpg" STYLE="position:absolute;TOP:0pt;LEFT:0pt;width=103;height=28;Z-INDEX:2;"> </div> </body> </html>
目前document.layers已经作古,期盼document.all早日上西天!!