Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery UI - Draggable Events</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script> <style> body{font-family:Arial, sans-serif; padding:20px;} #box{width:120px;height:70px;background:#04AA6D;color:#fff;display:flex;align-items:center;justify-content:center;border-radius:6px;cursor:move;margin-bottom:16px;} #status{font-weight:bold;} </style> </head> <body> <h3>start / drag / stop events</h3> <div id="box">Drag me</div> <div id="status">Status: idle</div> <script> $(document).ready(function(){ $("#box").draggable({ start: function(event, ui){ $("#status").text("Status: drag started"); }, drag: function(event, ui){ $("#status").text("Status: dragging at top=" + Math.round(ui.position.top) + ", left=" + Math.round(ui.position.left)); }, stop: function(event, ui){ $("#status").text("Status: drag stopped at top=" + Math.round(ui.position.top) + ", left=" + Math.round(ui.position.left)); } }); }); </script> </body> </html>
Output