简体   繁体   English

如何使用Jquery使内部div触发对外部div的拖动效果?

[英]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来拖动外部div,例如:

<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. 如果这是我的代码,假设附加了正确的JQuery插件以使用draggable等...我怎么能这样做,以便当用户点击并拖动innerDiv时,它会拖动整个outerDiv。 But so that when the user clicks and tries to drag the outerDiv, it doesn't work. 但是,当用户单击并尝试拖动outerDiv时,它不起作用。

Basically I want the innerDiv to control the draggability of the outerDiv. 基本上我希望innerDiv控制outerDiv的可拖动性。

Any Ideas? 有任何想法吗?

Thanks, 谢谢,
Matt 马特

You should take a look at the handle property for draggable . 你应该看一下draggablehandle属性。 Something like this (untested): 像这样(未经测试):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用内部div拖动外部父div? - How can I use an inner div to drag it's outer parent div? 点击内部 div 触发外部 div 事件 - clicking inner div to trigger outer div event 单击内部元素时如何停止外部div事件的触发器? 并且所有事件都绑定到$(document.body) - how can I stop the trigger of the outer div event when I click the inner element? And all the events are bound to $(document.body) 我如何才能对必须消失的div施加淡入淡出效果,对使用JQuery替换它的div施加淡入效果? - How can I apply a fadout effect to a div that have to disappear and a fade in effect to a div that replaces it using JQuery? 如何使带有溢出的内部div:滚动保持在外部div内? - How to make inner div with overflow:scroll stay inside outer div? 如何使用 javascript / jQuery 根据内部 div 元素内容/值对 div 元素进行排序? - How can I sort div elements based on inner div element content / values using javascript / jQuery? JavaScript 给定一个外部 div 和一个内部 div 的纵横比,我如何计算内部 div 的最大尺寸 - JavaScript given an outer div and an aspect ratio for an inner div, how do I calculate the maximum size of the inner div 如何使用jQuery在外部div的鼠标悬停上显示内部 - how to show inner on mouse hover of outer div with jquery jQuery UI:我怎么知道div集中在拖动事件上 - jQuery UI : How can I know that the div are center on drag event 如何让这个div上下滑动悬停效果? - How can I make this div slide up and down hover effect?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM