user6538837 user6538837 - 5 months ago 29
jQuery Question

Is there a way to limit the area which can be dragged? (JQuery UI Draggable)

https://jsfiddle.net/vpe9yLv7/1

$(document).ready(function(){
$( "#box" ).draggable({containment: "#container"});
});


As you can see, I have a box which I can drag throughout the body. However, is it possible to only be allowed to drag it when the user selects the purple part with an id of head?

Answer

Use handle

$( ".selector" ).draggable({
  handle: "#head"
});
Comments