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 Handle</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{position:relative;width:150px;height:90px;background:#04AA6D;color:#fff;border-radius:6px;text-align:center;padding-top:30px;} .handle{position:absolute;top:0;left:0;right:0;height:20px;background:rgba(0,0,0,.25);border-radius:6px 6px 0 0;cursor:move;} </style> </head> <body> <h3>handle: '.handle' (only the dark bar starts the drag)</h3> <div id="box"> <div class="handle"></div> Drag by the top bar only </div> <script> $(document).ready(function(){ $("#box").draggable({ handle: ".handle" }); }); </script> </body> </html>
Output