How to prevent Resizable and Draggable elements from collapsing on each other?

百般思念 提交于 2019-11-30 14:17:26

In my specific case, here is what I did to fix it:

resizeableObj.resizable({
    start: function(event, ui) {        
        resizeableObj.css({
            position: "relative !important",
            top: "0 !important",
            left: "0 !important"
        });
    },
    stop: function(event, ui) {
        resizeableObj.css({
            position: "",
            top: "",
            left: ""
        });
    }
});

As you can see, in the resizable start event, set the position to relative (by using draggable and resizable in concert, an absolute positioning is added) and set the top and left to 0 to prevent the "jumping" that you sometimes see. In the stop event, reverse these changes. Works in my case, YMMV.

Found a simpler solution (that fits my needs);

Inside jquery-ui.css, set the desired position and add !important to make sure it stays:

.ui-resizable {position: fixed !important} /* fix jquery's position absolute on resizing */

Use this code to keep the element within the window space without scrolling while dragging:

$("#draggable").draggable({containment:"window", scroll: false})

kippsoftware

Chrome Developer Tools indicates that jQuery UI uses the style="position:relative" attribute while the user is dragging/resizing. This will override any .demo{position:absolute} in the CSS.

The workaround is to set your own style="position:absolute" (you can use jQuery css() method for this) then explicitly set top and left for each div.

 $('.demo').css({position:"absolute"});

Just set the #container to position: relative;. http://jsfiddle.net/g7Cgg/1/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!