Js实现拖动窗口操作
思路:首先需要一个可拖动的窗口,也就是absolute定位的div。主要运用到onmousedown,onmouseup,onmousemove操作。
1.创建一个div,代码如下;
<style>
#demo {
width: 200px;
height: 200px;
background: rgb(137, 172, 97);
position: absolute;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<div id="demo">
噜噜噜
</div>
2.监听onmousedown,onmouseup,onmousemove.
<script>
let demo = document.querySelector('#demo')
let canMove = false
demo.onmousedown = function () {
canMove = true
console.log('down');
}
window.onmouseup &