<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<style>
.container {
600px;
height: 600px;
background-color: aquamarine;
position: relative;
}
.a {
100px;
height: 100px;
background-color: yellowgreen;
position: absolute;
}
.dragging {
background-color: red;
}
</style>
</head>
<body>
<div class='container' id='container'>
<div class="a"></div>
</div>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script>
d3.selectAll(".a").call(
d3.drag()
.on('start', function(d) {
d3.select(this).classed("dragging", true)
console.log('start')
})
.on("end", function (d) {
d3.select(this).classed("dragging", false)
console.log("end");
})
.on('drag', function(d) {
console.log(d3.select(this))
d3.select(this)
.style("left", function() {
return d.x + 'px'
})
.style("top", function() {
return d.y + 'px'
});
})
)
</script>
</body>
</html>