首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Resizable不适用于Droppable和Resizable的div

Resizable不适用于Droppable和Resizable的div
EN

Stack Overflow用户
提问于 2015-03-27 22:16:32
回答 1查看 359关注 0票数 0

这一切都运行得很好,现在我的需求改变了,我放入的.draaa项的div也必须是可调整的。因此,我将我的项目放在一个可丢弃和可调整大小的DIV中。

选项容器:' #GridDiv‘不再起作用了,但是当#GridDiv dident上有可调整的大小时,它就起作用了。因此,当我调整我的GridDiv的大小时,被拖放的元素也应该调整大小,但不能大于'#GridDiv‘。

有谁有主意吗?如果你浏览一下代码,你就会明白。

代码语言:javascript
复制
    $(".draaa").draggable({
    helper: 'clone',
    stop: function(ui, event){
        var stop = $(this).position();
        $(this).attr('data-component-x', stop.left);
        $(this).attr('data-component-y', stop.top);
        }
    });

     $('#GridDiv').resizable();

    $("#GridDiv").droppable({
    accept: '.draaa',
    drop: function(event, ui) {
        i ++;
        var getClone = $(ui.draggable).clone();
        getClone.attr("id",i+"_"+getClone.attr('id'));
        var hela_cid =getClone.attr("id");
        var deladcid = hela_cid.split("_");
        var cid = deladcid[2];
        var stop = $(getClone).position();
        var widthpx = getClone.css('width');
        var heightpx = getClone.css('height');
        var width = parseInt(widthpx, 10);
        var height = parseInt(heightpx, 10);

        var draggableDocumentOffset = ui.helper.offset();
        var droppableDocumentOffset = $(this).offset();
        var left = draggableDocumentOffset.left - droppableDocumentOffset.left;
        var top = draggableDocumentOffset.top - droppableDocumentOffset.top;
        getClone.css("left",left);
        getClone.css("top", top);
        getClone.css("position", "absolute");


        $(this).append(getClone);

        $("#GridDiv .draaa").addClass("item");

        $(".item").removeClass("ui-draggable draaa");
        $(".item").draggable({
            containment: '#GridDiv',
            //grid: [10,10],
            stop: function(ui, event){

            var stop = $(this).position();
            $(this).attr('data-component-x', stop.left);
            $(this).attr('data-component-y', stop.top);
        },
        }).resizable({

            helper: "ui-resizable-helper",

这样做是可行的

代码语言:javascript
复制
         //containment: '#GridDiv',
代码语言:javascript
复制
            //maxHeight: parseInt(MaxHeight),
            //maxHeight: 300,

            stop: function(event, ui) {
                var width = ui.size.width;
                var height = ui.size.height;
                $('#'+hela_cid).attr('data-component-width', width);
                $('#'+hela_cid).attr('data-component-height', height);
                }
        });


    }

});

这一行被注释掉了。所以我可以将.draaa组件的大小调整到比父组件'#GridDiv‘更大,但我不想这样做。

EN

回答 1

Stack Overflow用户

发布于 2015-03-27 22:56:40

好了,我找到了为什么它不起作用:/

代码语言:javascript
复制
}).resizable({
            //helper: "ui-resizable-helper",
            containment: '#GridDiv',

帮助器选项让它没有发生,为什么?我不知道。因此,我将不使用helper选项:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29302821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档