繁体   English   中英

如何停止可拖动元素Jquery Ui的大小调整?

[英]How to stop the resize for a draggable element Jquery Ui?

我有一个工作区,可以在其中拖放元素并调整其大小。

$(objName).draggable({
    start: function (ev, ui) {$(this).css({opacity:0.3})},

    cursor:'move',
    containment: 'parent',
    snap:true,
    stop: function (ev, ui) {
        $(this).css({opacity:1});
        var pos = $(ui.helper).offset();
        console.log($(this).attr("id"));
        console.log(pos.left)
        console.log(pos.top)
    }
})
.resizable({ghost:true,

});

但是,如果我开始调整大小,则无法通过工作区域的边界确定大小。

您需要做的就是将Element以及可拖动对象限制在调整大小上,就像这样

$(objName).draggable({
    start: function (ev, ui) {$(this).css({opacity:0.3})},

    cursor:'move',
    snap:true,
    drag: function(e, ui){
        var topRightCornerPos_x = $(this).css('left') + $(this).width();
        var bottomLeftConerPos_y = $(this).css('top') + $(this).width();

        if(topRightCornerPos_x > $(this).parent().width()){
            var maxLeft = $(this).parent().width() - $(this).width();
            $(this).css('left', maxLeft);
        }
        if(bottomLeftConerPos_y  > $(this).parent().height()){
            var maxTop = $(this).parent().height() - $9this).height();
            $(this).css('top', maxTop);
        }
    },
    stop: function (ev, ui) {
        $(this).css({opacity:1});
        var pos = $(ui.helper).offset();
        console.log($(this).attr("id"));
        console.log(pos.left)
        console.log(pos.top)
    }
})
.resizable({ghost:true,
    containment: $('#workingarea_id')
});

或者再次可以在可调整大小的参数中使用containment: 'parent'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM