Jquery Draggable UI overrides normal browser behavior for HTML elements inside draggable-enabled div

半腔热情 提交于 2020-01-05 05:42:07

问题


I have a jquery ui draggable div, and the HTML contents do not behave normally because of the draggable.

<div id="popup"> <!-- this popup is draggable -->
    This text is not selectable. When I try to select it, the popup div is dragged.
    <div style="overflow:auto; height:50px">
         Lots of text here, vertical scrollbar appears. But clicking the scrollbars don't work (doesn't scroll the content). Each click (mousedown-mouseup) is considered "dragging".
    </div>
</div>

How do I prevent the draggable ui to override the normal browser behavior for HTML elements?


回答1:


You can disable dragging from the inner <div> like this:

$("#popup div").bind('mousedown mouseup', function(e) {
  e.stopPropagation();
});

event.stopPrpagation() stops a click on that inner <div> from bubbling up to the outer <div> that has the drag events bound to it. Since the event will never get there, those drag event handlers won't interfere. You can run this code before or after creating the draggable, it'll work either way.




回答2:


Try add your div unselectable attribute=off:

<div id="popup" unselectable="off">
...

and css:

[unselectable=off] { 
    -moz-user-select                    : all; 
    -khtml-user-select                  : all; 
    user-select                     : all; 
}

I'm not tested in jQuerry.UI, but this is my workaround in extJs and Dojo...



来源:https://stackoverflow.com/questions/3227819/jquery-draggable-ui-overrides-normal-browser-behavior-for-html-elements-inside-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!