简体   繁体   English

jQuery UI可调整大小的添加不必要的边距

[英]jQuery UI-Resizable Adding an Unwanted Margin

jQuery UI "resizable" adds a 10 pixel handle to the right and bottom of an element. jQuery UI“可调整大小”在元素的右侧和底部添加了10像素的句柄。 See example here: http://jsfiddle.net/Thaikhan/fGJ59/10/show/ 在此处查看示例: http : //jsfiddle.net/Thaikhan/fGJ59/10/show/

If you click on Pikachu, then try to drag him into the bottom right corner, he doesn't fit flush because of the handle margin. 如果单击“皮卡丘”,然后尝试将其拖到右下角,则由于手柄余量,他不适合齐平。

I want the images to be able to fit flush against the border. 我希望图像能够与边框齐平。 I've tried to disable the handle but have been unable to retain resizability while removing the border. 我试图禁用该句柄,但在删除边框时无法保持可缩放性。

If this isn't possible, perhaps there's a way to add 10px to the right and bottom margin of the container and have the elements go through the border? 如果无法做到这一点,也许有一种方法可以在容器的右侧和底部边缘添加10px并使元素穿过边界?

Thanks for your help! 谢谢你的帮助!

Here is the relevant jQuery: 这是相关的jQuery:

$('.inventory').on('click', 'img', function () {
$(this).resizable({
    aspectRatio: 1,
    autoHide: true,
    // containment: "parent",
    minHeight: 50,
    minWidth: 50,
    maxHeight: 300,
    maxWidth: 400
});

$(this).parent().appendTo(".frame").draggable({
    containment: "parent",
    cursor: "move"
});

refreshIndexList();
zindex();
});

Because you're working with the images directly resizable is wrapping them in a div and adding space for the handle. 由于您正在使用直接调整大小的图像,因此将它们包装在div中并为手柄添加空间。 If you wrap the images in a div yourself, set resizable on the div and set the image to also resize you can get the desired effect. 如果您自己将图像包装在div中,请在div上设置可调整大小,并将图像设置为也可以调整大小,以获得所需的效果。 The handle will hover over the image and the image will be flush to the side. 手柄将悬停在图像上方,并且图像将齐平到侧面。

The changes: 变化:

.frame img {
    position: relative;
    height : 50px;
    width: 50px;
}

You need to get rid of the top and left positioning, they don't seem to be doing anything and they mess things up when you wrap the image in a div. 您需要摆脱顶部和左侧的位置,它们似乎没有做任何事情,而且当您将图像包装在div中时,它们使事情变得混乱。

$('.inventory').on('click', 'img', function () {
    $(this).wrap('<div style="height:50px;width:50px;"></div>');
    $(this).parent().resizable({
        aspectRatio: 1,
        alsoResize:this,
        autoHide: true,
        containment: "parent",
        minHeight: 50,
        minWidth: 50
    });

    $(this).parent().appendTo(".frame").draggable({
        containment: "parent",
        cursor: "move"
    });

    refreshIndexList();
    zindex();
});

Wrap the image in a div when it's added to the frame. 将图像添加到框架后,将其包装在div中。

$('.frame').on('dblclick', '.ui-draggable', function () {
    $(this).find('img').appendTo(".inventory").attr('style', '');
    $(this).draggable("destroy");
    $(this).resizable("destroy");
    $(this).remove();
    refreshIndexList();
    zindex();
});

And then break the image out of the div when you put it back. 然后将图像放回div中时,将其断开。

http://jsfiddle.net/fGJ59/13/ http://jsfiddle.net/fGJ59/13/

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

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