

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
margin: 0;
padding: 0;
}
.container {
width: 400px;
height: 200px;
background-color: lightblue;
display: flex;
align-items: center;
justify-content: center;
position: relative;
margin-top: 100px;
margin-left: 100px;
}
</style>
</head>
<body>
<div class="container" id="container">
</div>
<script>
window.onload = function () {
const child = document.getElementById('child');
child.addEventListener('mousedown', function (e) {
console.log('mousedown:', e);
})
child.addEventListener('mousemove', function (e) {
console.log('mousemove:', e);
})
child.addEventListener('mouseup', function (e) {
console.log('mouseup:', e);
// clientX 305 clientY 201
// layerX 197 layerY 101
// offsetX 47 offsetY 52
})
}
</script>
</body>
</html>
以前答过的贴,贴找不到了,代码还在,是这个?
tips
拖拉框选同时按shift
或者alt
可以实现AND
和OR