【问题标题】:Resizable iframes jquery可调整大小的 iframe jQuery
【发布时间】:2013-08-15 19:51:02
【问题描述】:

我想在使用 HTML5 时拥有一个 <frameset>,我设法使用 html 代码创建了一些东西,我想让两个 iframe 可调整大小但也并排放置,我在两个 iframe 之间遇到了问题,因为我的代码让它们独立调整大小,我希望调整大小,就像在旧的 <frameset> 中实现的那样。

这是我的html代码:

<body>
    <div class="resizable1">
        <iframe class="menu" src="menu.html"></iframe>
    </div>
    <div class="resizable2">
        <iframe class="mainContent" src="events.html"></iframe>
    </div>
</body>

这是我的CSS:

.ui-resizable-helper {
    border: 1px dotted gray;
}

.resizable1 {
    float: left;
    width: 20%;
    height: 80%;
    display: block;
    border: 2px solid gray;
    overflow: hidden;
    position: relative;
}

.resizable2 {
    float: left;
    width: 75%;
    height: 80%;
    display: block;
    border: 2px solid gray;
    overflow: hidden;
    position: relative;
}

.menu {
    float: left;
    width: 20%;
    height: 80%;
}

.mainContent {
    float: left;
    width: 75%;
    height: 80%;
}

这是我的 jQuery 脚本:

$(function() {
        $(".resizable1").resizable({
            animate : true,
            animateEasing : 'swing',
            imateDuration : 500
        });
        $(".resizable2").resizable({
            animate : true,
            animateEasing : 'swing',
            imateDuration : 500
        });
    });
</script>

【问题讨论】:

  • 一个 jsFiddle 非常适合这个
  • iFrame 仅用于跨域使用,例如您网站上的 youtube 视频或 facebook 墙。不要将 iFrame 用于本地文件,有更好的方法来显示网站内容。

标签: jquery css iframe frameset


【解决方案1】:

我同意上述观点,我建议手动调整它们的大小,但如果你想保留动画,也许可以这样做:(使用包含属性限制高度并尝试计算新的宽度需要在第一个调整大小后手动调整第二个)

JSFiddle

在 HTML 中添加了一个容器:

<div id="container">
    <div class="resizable1">
        <iframe class="menu" src="www.google.com">
            bla
        </iframe>
    </div>
    <div class="resizable2">
        <iframe class="mainContent" src="www.yahoo.com"></iframe>
    </div>
</div>

在 CSS 中设置高度:

.ui-resizable-helper {
    border: 1px dotted gray;
}
#container{
    height: 500px;
    width: 600px;
}
.resizable1 {
    float: left;
    width: 20%;
    height: 100%;
    display: block;
    border: 2px solid gray;
    overflow: hidden;
    position: relative;
}

.resizable2 {
    float: left;
    width: 75%;
    height: 100%;
    display: block;
    border: 2px solid gray;
    overflow: hidden;
    position: relative;
}

.menu {
    float: left;
    width: 20%;
    height: 80%;
}

.mainContent {
    float: left;
    width: 75%;
    height: 80%;
}

在 jquery 中手动调整大小(抱歉,不能完全工作,希望对您有所帮助)

$(function() {
        $(".resizable1").resizable({
            animate : true,
            animateEasing : 'swing',
            imateDuration : 500,
            containment: '#container'
        });
        $(".resizable2").resizable({
            animate : true,
            animateEasing : 'swing',
            imateDuration : 500,
            containment: '#container'
        });
    $(".resizable1").resize(
        function(e){
            var fullWidth = $("#container").innerWidth();
            var r1Width = $(".resizable1").outerWidth();
            $(".resizable2").width(fullWidth - r1Width-6);
            var r2Width = $(".resizable2").outerWidth();
            console.log(r1Width+" + "+r2Width+" = "+fullWidth);
        }
    );
});

【讨论】:

    猜你喜欢
    • 2010-11-17
    • 1970-01-01
    • 2014-06-04
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 2012-12-05
    • 1970-01-01
    相关资源
    最近更新 更多