当前位置:网站首页>JS realizes modal box dragging
JS realizes modal box dragging
2022-04-23 06:53:00 【zjLOVEcyj】
<!DOCTYPE html>
<html lang="zh-CN">
<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> Modal box drag </title>
<style> body {
position: relative; } div {
position: absolute; left: 0; top: 0; width: 200px; height: 200px; background-color: pink; } </style>
</head>
<body>
<div>
<h1> Click here to drag </h1>
</div>
<script> h1 = document.querySelector('h1') div = document.querySelector('div') h1.addEventListener('mousedown', (e) => {
let x = e.pageX - div.offsetLeft let y = e.pageY - div.offsetTop function move(e) {
div_x = e.pageX - x + 'px' div_y = e.pageY - y + 'px' div.style.left = div_x div.style.top = div_y } document.addEventListener('mousemove', move) h1.addEventListener('mouseup', () => {
document.removeEventListener('mousemove', move) }) }) </script>
</body>
</html>
版权声明
本文为[zjLOVEcyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555334026.html
边栏推荐
- 压力测试工具 Jmeter
- 小米摄像头异常解决
- 并发优化请求
- New type of dark energy could solve Universe expansion mystery
- Batch modify / batch update the value of a field in the database
- .Net Core3.1 使用 RazorEngine.NetCore 制作实体生成器 (MVC网页版)
- Each traversal usage of tp6
- C# 监听WMI事件
- leetcode刷题之x的算术平方根
- The difference between VaR, let and Const
猜你喜欢
随机推荐
freeCodeCamp----arithmetic_arranger练习
【代码解析(1)】Communication-Efficient Learning of Deep Networks from Decentralized Data
A website that directly downloads PNG icons without logging in
条形码与二维码的生成
JQ序列化后PHP后台解析
【代码解析(2)】Communication-Efficient Learning of Deep Networks from Decentralized Data
PHP background parsing after JQ serialization
ASP.NET CORE JWT认证
ASP.NET CORE3.1 Identity注册用户后登录失败的解决方案
常用网站汇总
.Net Core 下使用 Quartz —— 【1】快速开始
初步认识Promse
el-date-picker限制选择范围,从当前时间到两个月前
Promise(四)
postMan 传参总结
批量修改/批量更新数据库某一个字段的值
ASP.NET CORE 依赖注入服务生命周期
TP5 uses redis
Leak detection and vacancy filling (V)
微信小程序









