javascript image following mouse movement effect method
- 2020-06-12 08:33:33
- OfStack
An example of javascript shows how to implement the effect of mouse movement. Share to everybody for everybody reference. Specific implementation methods are as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> The picture follows the mouse </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 />
Quietly following the mouse over ~~
</div>
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.