简体   繁体   English

一个可拖动/可调整大小的div与iframe子,它延伸到父级,带有一些填充/边距?

[英]A draggable/resizable div with iframe child that stretches to parent with some padding/margin?

The jsfiddle: http://jsfiddle.net/nEzfQ/ jsfiddle: http//jsfiddle.net/nEzfQ/

The iframe should stretch to the parent div size with some padding or margin.. what's wrong with this? iframe应该延伸到父div大小,带有一些填充或边距..这有什么问题?

<div class="outer ui-widget-content">
    <iframe src="about:blank"></iframe>
</div>

iframe {
    display: block;
    position:absolute;
    bottom:0;
    top:0;
    left:0;
    right:0;
    margin: 20px;
    padding: 0;
    border: none;
    background-color: green;
}

.outer {
    top: 20px;
    left: 30px;
    position: absolute;
    width: 300px;
    height: 200px;
}

What I am trying to achieve: parent div that acts as a frame/border that can be used to drag/resize the iframe.. 我想要实现的目标:父div作为框架/边框,可用于拖动/调整iframe的大小。

Caveat: I need the size of the outer div to be the real size, no padding or margin to it. 警告:我需要外部div的大小为实际大小,没有填充或边距。

I'm not sure you can actually achieve this with CSS only. 我不确定你只能通过CSS实现这一点。 I suggest you try a walkaround using JS listener over the resizable element. 我建议你在可调整大小的元素上使用JS监听器尝试一下。

$("#container").resizable({
    stop: function (event, ui) {
        $("#dim").text(JSON.stringify(ui.size));
        $("#myiframe").width(ui.size.width).height(ui.size.height);

    }
});

http://jsfiddle.net/nEzfQ/1/ http://jsfiddle.net/nEzfQ/1/

jsFiddle Demo jsFiddle演示

With Output 随着输出

$("#outerdims").val(JSON.stringify({
    height: $(".outer").height(),
    width: $(".outer").outerWidth(true)
}));
$("#iframedims").val(JSON.stringify({
    height: $("iframe").height(),
    width: $("iframe").outerWidth(true)
}));
$(".outer").resizable({
    resize: function (event, ui) {
        var newWd = ui.size.width - 20;
        var newHt = ui.size.height - 20;
        $("iframe").width(newWd).height(newHt);
        $("#outerdims").val(JSON.stringify({
            height: $(".outer").height(),
            width: $(".outer").outerWidth(true)
        }));
        $("#iframedims").val(JSON.stringify({
            height: $("iframe").height(),
            width: $("iframe").outerWidth(true)
        }));
    }
}).draggable();

Without Output 没有输出

$(".outer").resizable({
    resize: function (event, ui) {
        var newWd = ui.size.width - 20;
        var newHt = ui.size.height - 20;
        $("iframe").width(newWd).height(newHt);
    }
}).draggable();

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

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