How to drag two pictures in canvas

drawImage loop draws two pictures. How to drag and drop
clipboard.png

separately.
Apr.15,2022

generate two canvas, one picture is drawn on a canvas


mousedown , iterate through your two pictures, determine which picture the current mouse is on according to the coordinates, and then set the picture as the drag object. Then when mousemove , modify the coordinates of the drag object. When mouseup , just set the drag object to empty.


it is recommended to use the fabric.js library. Using native libraries requires consideration of location, and when stacked together, there are many things to consider. Fabric.js has been implemented

.
Menu