Jquery ui, draggable containment parent+rectangle?

依然范特西╮ 提交于 2019-12-25 05:14:53

问题


I want to have a draggable that is contained within it's parent, and then I want to restrict it further to stay within a certain rectangle within the parent:

item.draggable({containment:"parent",axis:"x",handle:item.children()});
item.draggable('option','containment')
"parent"

item.draggable('option','containment',[0,0,250,0]);
item.draggable('option','containment')
[0,0,250,0]

I want it to be both "parent" and [0,0,250,0] at the same time, but the problem is that as soon as I set the containment option it forgets the parent containment that I created it with. When it forgets the parent the rectangle is figured with respect to the document, and the parent is typically not located at x=0.

Edit: Ok, so I solved the problem, but I still want some input because this is really strange behavior. When I initialize the draggable the containment option is set to the string "parent", then if I set it to something else it will be something else and it will forget about the parent. However if I first drag the draggable and then set it to something else the item.draggable('option','containment') will output a dom element, so that apparently the "parent" got processed into something else. Then if I set the containment option to something else after having first dragged the item it will remain contained to parent even when the containment is set to a rectangle, which solves my problem. Now I'm wondering if this is a bug or a design issue and shouldn't this behavior be better documented? Anyone out there? #slowtuesday

来源:https://stackoverflow.com/questions/10498837/jquery-ui-draggable-containment-parentrectangle

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