【发布时间】:2011-05-03 22:49:16
【问题描述】:
我在页面上有一个 jQueryUI 可拖动对象和一个可排序对象。
将一个元素从可拖动元素拖到可排序元素会导致被拖动的元素跳到页面的左上角。
这是演示:http://jsfiddle.net/travisrussi/aBhDu/1/
复制:
- 将“项目 5”从可拖动 div(顶部框)拖到可排序 div(底部框)
实际结果:
- 当拖动到可排序对象上时,项目 5 会跳转到左上角 - http://i.stack.imgur.com/474OP.jpg
拖动的元素似乎从相对定位切换到绝对定位。拖拽的“li”切换自:
<li class="ui-state-default ui-draggable" style="position: relative; left: 52px; top: 9px;">Item 3</li>
到这里:
<li class="ui-state-default ui-draggable ui-sortable-helper" style="position: absolute; left: 67px; top: 91px; width: 80px; height: 20px;">Item 3</li>
当可拖动项被拖入可排序对象时。
这是来自 jQueryUI 1.8.12 的相关 sn-p(从第 3041 行开始):
//The element's absolute position on the page minus margins
this.offset = this.currentItem.offset();
this.offset = {
top: this.offset.top - this.margins.top,
left: this.offset.left - this.margins.left
};
// Only after we got the offset, we can change the helper's position to absolute
// TODO: Still need to figure out a way to make relative sorting possible
this.helper.css("position", "absolute");
this.cssPosition = this.helper.css("position");
$.extend(this.offset, {
click: { //Where the click happened, relative to the element
left: event.pageX - this.offset.left,
top: event.pageY - this.offset.top
},
parent: this._getParentOffset(),
relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
});
//Generate the original position
this.originalPosition = this._generatePosition(event);
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;
是否有一些我没有使用的配置选项?
CSS 有问题吗?
或者这是 jqueryUI 中的错误?
【问题讨论】:
-
你链接到正确的小提琴了吗?我在演示中看到的布局与您的屏幕截图中的不同。
-
@Andrew:感谢您指出这一点。链接已修复。
-
看起来 JS 无法正常工作——仔细检查后,看起来脚本需要不同的 HTML?不确定。
标签: jquery jquery-ui drag-and-drop jquery-ui-sortable jquery-ui-draggable