本文實例講述了javascript實現圖片跟隨鼠標移動效果的方法。分享給大家供大家參考。具體實現方法如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>圖片跟著鼠標走</title> <script type="text/javascript"> function DivFlying() { var div = document.getElementById("divFly"); if (!div) { return; } var intX = window.event.clientX; var intY = window.event.clientY; div.style.left = intX + "px"; div.style.top = intY + "px"; } document.onmousemove = DivFlying; </script> </head> <body> <div id="divFly" style="position:absolute;"> <img src="fly.gif" /><br /> 低調的跟著鼠標飄過~~ </div> </body> </html>希望本文所述對大家的javascript程序設計有所幫助。