0

以此为例。

http://jsbin.com/ufarif/6/

如果左侧位置小于 80,我想冻结元素不被拖动到左侧。但是,如果我返回 false,则用户根本无法拖动元素(甚至向右拖动)。

handle.draggable('disable');stop在触发事件之前完全忽略。

returnreturn true不停止拖动。

请注意,我知道该containment选项,但是,我的条件是动态的,containment并且不将函数作为参数。

4

1 回答 1

0

您可以覆盖被拖动元素的位置。

这个小提琴是位置覆盖的一个例子:http: //jsfiddle.net/QvRjL/74/

这个小提琴是一个例子,你可以如何检查拖动的元素是否靠近容器的边框:http: //jsfiddle.net/pPn3v/22/

$(document).mousemove(function(e){
   window.mouseXPos = e.pageX;
   window.mouseYPos = e.pageY;
}); 

$('[id^="drag-"]').each(function() {
    $(this).draggable({
        opacity: 0.7,
        cursorAt: { top: 15, left: 50 },        
        scroll: true,
        stop: function(){},  
        drag : function(e,ui){            
            //Force the helper position
            ui.position.left = window.mouseXPos - $(this).draggable('option','cursorAt').left;
            ui.position.top = window.mouseYPos- $(this).draggable('option','cursorAt').top; 
        });
});
于 2012-10-22T07:17:41.963 回答