Witam,
mam problem, mianowicie podczas ruchu, przenoszenia obiektu, obiekt dostawia się po prawej stronie myszki od dołu.
Jak zniwelować ten efekt?
Głowie się już cały dzień
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<title>Drag/Drop/Bounce</title>
<style>
#container {
width: 100%;
height: 400px;
background-color: #333;
overflow: hidden;
border-radius: 7px;
touch-action: none;
position: relative;
}
#item, #item2 {
width: 100px;
height: 100px;
background-color: rgb(245, 230, 99);
border: 10px solid rgba(136, 136, 136, .5);
border-radius: 50%;
touch-action: none;
user-select: none;
position: absolute;
top: 100px;
left: 400px;
}
#item:active, #item2:active {
background-color: rgba(168, 218, 220, 1.00);
}
#item:hover, #item2:hover {
cursor: pointer;
border-color: rgba(168, 218, 220, .70);
}
</style>
</head>
<body>
<div id="outerContainer">
<div id="container">
<div id="item2">
</div>
</div>
</div>
<script>
class Move {
constructor(element) {
this.element = undefined;
this.draggable = undefined;
this.getElement(element);
this.initDraggable();
this.moveDraggable();
this.removeDraggable();
}
getElement(element) {
this.element = document.querySelector(element);
}
initDraggable() {
this.element.onmousedown = () => {
this.draggable = this.element;
}
}
moveDraggable() {
document.onmousemove = (e) => {
let mouseDownX = e.clientX;
let mouseDownY = e.clientY;
if (this.draggable == undefined)
return;
this.draggable.style.left = mouseDownX + "px";
this.draggable.style.top = mouseDownY + "px";
}
}
removeDraggable() {
document.onmouseup = (e) => {
this.draggable = undefined;
}
}
}
new Move('#item2');
</script>
</body>
</html>