[英]jQuery UI Draggable: Stack on Click
Is there any way to kick off a draggable
's stack procedure when it is clicked, not just dragged? 有没有什么方法可以在点击它时启动
draggable
的堆栈程序,而不仅仅是拖动?
I found this solution, which basically tries to just copy the library code. 我找到了这个解决方案,它基本上只是试图复制库代码。 (It is also missing an important piece which I inserted below).
(它也缺少我在下面插入的重要部分)。 Is there not a more elegant solution?
有没有更优雅的解决方案?
Modifying the author's code, the following solution works: 修改作者的代码,以下解决方案有效:
function bringFront(elem, stack){
// Brings a file to the stack front
var min, group = $.makeArray($(stack)).sort(function(a, b) {
return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0);
});
if(group.length < 1) return;
min = parseInt(group[0].style.zIndex, 10) || 0;
$(group).each(function(i) {
this.style.zIndex = min+i;
});
if(elem == undefined) return;
$(elem).css({'zIndex' : min+group.length});
}
But it would obviously be better to call the library method somehow. 但是以某种方式调用库方法显然会更好。
Found a solution by hacking the jquery draggable widget: 通过黑客攻击jquery draggable小部件找到了解决方案:
$('#myDraggable').click(function(event){
var widget = $('#myDraggable').data('ui-draggable');
widget._mouseStart(event);
widget._mouseDrag(event);
widget._mouseStop(event);
});
Have you simply tried triggering the draggable stack off a click? 您是否只是尝试通过点击触发可拖动堆栈?
$('#target').on("click", function() {
$( this ).draggable({ stack: "#products" });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.