简体   繁体   中英

How can I make an inner div trigger a drag effect on an outer div using Jquery?

I want to use an inner div to drag around an outer div, for example:

<div id="outerDiv" style="height:300px; width:200px;">
     <div id="innerDiv" style="height:10px; width:200px;"></div>
</div>

If this is my code, assuming the proper JQuery plugins are attached to use draggable, etc... How can I make it so that when the user clicks and drags the innerDiv, it drags the entire outerDiv. But so that when the user clicks and tries to drag the outerDiv, it doesn't work.

Basically I want the innerDiv to control the draggability of the outerDiv.

Any Ideas?

Thanks,
Matt

You should take a look at the handle property for draggable . Something like this (untested):

$("#outerDiv").draggable({ handle: "innerDiv" });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM