当前位置:网站首页>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 !!
边栏推荐
- Process finished with exit code-1073740791(0xC0000409)
- Qt development tips
- Tensorflow GPU installation process record
- Image steganography method
- Bcompare key expired or bcompare license key revoked
- Various pitfalls encountered in UI development
- Modify the default path of Jupiter notebook
- Search Pfam with Hmmer
- Hard disk partition method
- C language program: judging triangles
猜你喜欢

Examples of Pareto optimality and Nash equilibrium

看了就会的 Rainbond 入门教程
![[thread safety] what risks may multithreading bring?](/img/79/112ab7e586b0bceb296dfddb2728be.png)
[thread safety] what risks may multithreading bring?

Establishment and traversal of binary tree (implemented in C language)

MQTT入门级简单介绍与使用

Redis configuration file explanation

Penguin side: why not recommend using select *?

Multi merchant mall system function disassembly lecture 17 - platform side order list

Store and guarantee rancher data based on Minio objects

58 sub station Anju, broker marketing management platform login interface encryption reverse
随机推荐
QT qlineedit, qtextedit, qplaintextedit differences
SQL error [1810] [22008]: ora-01810: format code occurs twice
6、 C language circular statement
Vtkcellpicker picking triangular patches
SQL learning
Knowledge map Foundation (I) - what is knowledge map
The 35 required questions in MySQL interview are illustrated, which is too easy to understand
The second pre class exercise
Machine learning related concepts
SSH service
Swiftui 4.0's new navigation system
Several methods of opening URL in swiftui view
On July 29, apachecon | apachepulsar's exploration and practice in vivo will be broadcast soon
Reptile: from introduction to imprisonment (I) -- Concept
Penguin side: why not recommend using select *?
5、 C language judgment statement
Log management platform of infrastructure and nail & email alarm notification
[leetcode] sticker spelling (dynamic planning)
Product Manager
Added the ability of class @published for @cloudstorage