1.代码效果
当鼠标点击目标区域并且移动可以实现在网页的窗口内移动,鼠标松开之后停止。
2.代码及解释
详细解释在代码下部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./jquery-3.5.0.min.js"></script>
<style>
*{margin: 0px;padding: 0px;}
#hid{
width: 200px;
height: 200px;
background-color: aqua;
cursor: move;
position: absolute;
}
</style>
</head>
<body>
<div id="hid"></div>
</body>
<script>
$(function(){
$("#hid").mousedown(fu