<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>鼠标拖拽效果</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
/* cursor: pointer; */
width: 200px;
height: 200px;
background-color: deepskyblue;
position: relative;
}
</style>
</head>
<body>
<div></div>
<script>
var div = document.querySelector("div");
div.onmousemove = function () {
document.onmousemove = function () {
var event = event || window.event;
var x = event.clientX;
var y = event.clientY;
div.style.top = y - 100 + "px";
div.style.left = x - 100 + "px";
}
}
</script>
</body>
</html>
Js简单的鼠标跟随
最新推荐文章于 2024-11-14 14:55:48 发布