当前位置:网站首页>A problem -- about dragging div in JS, when I change div to round, there will be a bug
A problem -- about dragging div in JS, when I change div to round, there will be a bug
2022-07-28 15:03:00 【Dream rain in flowers】
An ordinary drag function :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
window.onload = function(){
var box1 = document.getElementById("box1")
box1.onmousedown = function(event){
// var obj = getComputedStyle(box1,null)
// alert(obj.width)
/* div Horizontal offset of = mouse .clientX - Elements .offsetLeft div Vertical offset of = mouse .clientY - Elements .offsetTop */
var ol = event.clientX - box1.offsetLeft
var ot = event.clientY - box1.offsetTop
// alert(" The mouse starts dragging ")
document.onmousemove = function(event){
// Follow the effect
var x = event.clientX -ol
var y = event.clientY - ot
box1.style.left = x + "px"
box1.style.top = y + "px"
}
// Loosen the mouse , Fixed position
box1.onmouseup = function(){
// alert(" I released the mouse ")
// Cancel document.onmousemove event
document.onmousemove = null
document.onmouseup = null
}
}
}
</script>
<style type="text/css">
#box1{
height: 100px;
width: 100px;
background-color: #0c0;
/* Turn the square into a circle */
/* border-radius: 50s%; */
position: absolute;
}
</style>
</head>
<body>
<div id="box1"></div>
</body>
</html>

The blame is on , I feel that this square is a little ugly , So let him pass boeder-rudius: 50% Change to round , You can also drag , You can also drag , But I can't release the mouse and fix it in a new position .
The video is as follows :
( It hasn't been approved yet )
It's weird !!
边栏推荐
- QT hex, decimal, qbytearray, qstring data conversion
- Word creates a title list with automatic numbering
- QT environment cannot run error set
- Solve blast database error: error pre fetching sequence data
- 7、 Detailed explanation of C language function definition
- Redis-持久化
- MLX90640 红外热成像仪传感器模块开发笔记(八)
- CONDA create, CONDA install, CONDA update error conda.core.subdir_ data.Response304ContentUnchanged
- Pytorch GPU installation
- 23、 TF coordinate transformation (III): dynamic coordinate transformation
猜你喜欢

VTK annotation class widget vtkborderwidget

2021-09-02

MQTT入门级简单介绍与使用

Product Manager

Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance

Penguin side: why not recommend using select *?

Picture Trojan principle production prevention

Mysql使用left join连表查询时,因连接条件未加索引导致查询很慢

Examples of Pareto optimality and Nash equilibrium

看了就会的 Rainbond 入门教程
随机推荐
Hard disk partition method
MySQL authorization method
How to perform batch operations in core data
Installing MySQL on Linux
VTK annotation class widget vtkborderwidget
Redis-Redis在Jedis中的使用
5、 C language judgment statement
Word creates a title list with automatic numbering
Error reason for converting string to long type: to convert to long type, it must be int, double, float type [easy to understand]
面试官:ThreadLocal使用场景有哪些?内存泄露问题如何避免?
Install scikit learn journey
Switch the cloud synchronization status of core data in real time
Enumeration type
7月29日 ApacheCon|Apache Pulsar 在 vivo 的探索与实践 即将开播
Redis redis use in jedis
How does core data save data in SQLite
Redis configuration file explanation
SSH service
9、 C array explanation
2、 Declaration and definition of variables and constants