Adr*_*sca 11 jquery jquery-ui css3 jquery-ui-sortable
我正在使用CSS转换扩展JQuery可排序元素.两个可排序的项目开始位置和偏移,而拖动是错误的,因为JQuery不考虑CSS标度.我用这里的代码部分解决了它:
但我无法解决的问题是拖动开始时的可排序项目位置.它向上跳了一下.我无法弄清楚要放入启动事件处理程序的内容:
start: function(e, ui)
{
// something is needed here to fix the initial offset
}
Run Code Online (Sandbox Code Playgroud)
这个小提琴显示了这个问题:http: //jsfiddle.net/adrianrosca/zbvLp/4/
与draggable的一个区别是变换不是在元素本身上,而是在父元素上.所以它改变了一点逻辑.
这是针对这种特定情况的解决方案,但您会看到根据情况可能会发生变化.例如,如果更改transform-origin,或者如果您具有水平排序,则必须进行调整.但逻辑保持不变:
var zoomScale = 0.5;
$(".container")
.sortable({
sort: function(e, ui) {
console.log(ui.position.left)
var changeLeft = ui.position.left - ui.originalPosition.left;
// For left position, the problem here is not only the scaling,
// but the transform origin. Since the position is dynamic
// the left coordinate you get from ui.position is not the one
// used by transform origin. You need to adjust so that
// it stays "0", this way the transform will replace it properly
var newLeft = ui.originalPosition.left + changeLeft / zoomScale - ui.item.parent().offset().left;
// For top, it's simpler. Since origin is top,
// no need to adjust the offset. Simply undo the correction
// on the position that transform is doing so that
// it stays with the mouse position
var newTop = ui.position.top / zoomScale;
ui.helper.css({
left: newLeft,
top: newTop
});
}
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/aL4ntzsh/5/
编辑:
以前的答案将适用于定位,但正如Decent Dabbler指出的那样,交叉函数存在一个缺陷,可以在进行排序时进行验证.基本上,正确计算位置,但项目保持未转换的宽度和高度值,这导致问题.您可以通过在开始事件上修改这些值来调整这些值,以考虑比例因子.像这样例如:
start: function(e, ui) {
var items = $(this).data()['ui-sortable'].items;
items.forEach(function(item) {
item.height *= zoomScale;
item.width *= zoomScale;
});
}
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/rgxnup4v/2/