简体   繁体   English

如何在启用了拖放的div中启用鼠标拖动

[英]How to enable mouse dragging within a drag and drop enabled div

I have a div with several elements inside (as expected), and I want to be able to drag and drop this div ( draggable=true ); 我有一个包含多个元素的div(如预期的那样),并且我希望能够拖放该div( draggable=true ); however, one element is a bar graph that allows a user to drag the mouse across it to select a certain range of data (sort of like how Stack Overflow allows you to view your reputation within certain date ranges--you can find it on your profile under your reputation tab). 但是,一个元素是一个条形图,它允许用户在其上拖动鼠标以选择特定范围的数据(类似于Stack Overflow如何让您查看特定日期范围内的声誉-您可以在自己的日期上找到它个人资料在“信誉”标签下)。 As you might imagine, I am unable to drag across this graph when its parent div has draggable set to true , since it just drags the div instead of updating the graph. 您可能会想到,当其父div的draggable设置为true时,我将无法在该图上draggable ,因为它只是拖动div而不是更新图。

I've thought of a number of hacks to get around this, but they all seem rather messy. 我想过很多办法可以解决这个问题,但是它们看起来都很混乱。 So I'm wondering what options I have that aren't so hackish. 所以我想知道我有哪些选项不那么扎实。 Ideally, I'd be able to drag the entire div by only being able to drag on part of the div. 理想情况下,我只能拖动部分div来拖动整个div。

Setting a "div" to draggable will cause it to be dragged whenever you drag any elements contained within that div. 将“ div”设置为可拖动时,只要您拖动该div中包含的任何元素,它就会被拖动。 One good way around this is to position the graph inside the div's space using absolute positioning rather than putting it inside the div tags. 解决此问题的一种好方法是使用绝对定位将图形放置在div空间内,而不是将其放置在div标签内。

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

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