在jQuery Masonry中调整iframe的高度(YouTube嵌入)

时间:2015-04-23 03:13:51

标签: javascript jquery iframe jquery-masonry masonry

总计noob,尝试将jquery砌体页面与嵌入的YouTube视频放在一起。

问题是,视频的高度没有调整,我无法弄清楚如何使比例正确。

我查看了以下链接,但我无法弄清楚如何将这些想法纳入我的代码中。

Jquery - How do I dynamically adjust height of iframe?
Adjust Height of iFrame When New Content is Loaded

我的整个代码块如下。您会注意到div对图像的调整很好,但无法针对嵌入的YouTube视频进行适当调整。

我哪里错了?任何帮助将不胜感激......

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Article Title</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<style>
body {
    font: 1em/1.67 Arial, Sans-serif;
    margin: 0;
    background: #e9e9e9;
}

img, iframe {
max-width: 100%;
height: auto;
display: block;
}

.wrapper {
    width: 95%;
    margin: 3em auto;
}

.masonry {
    margin: 1.5em 0;
    padding: 0;
    -moz-column-gap: 1.5em;
    -webkit-column-gap: 1.5em;
    column-gap: 1.5em;
    font-size: .85em;
}

.item {
    display: inline-block;
    background: #fff;
    padding: 1.5em;
    margin: 0 0 1.5em;
    width: 100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.18);
    border-radius: 3px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
}

.title, .footer {
text-align: center;
}

.title h1 {
margin: 0;
}

.title a {
display: inline-block;
padding: .75em 1.25em;
color: #888;
border: 2px solid #aaa;
margin: .25em 1em 1em;
text-decoration: none;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-ms-border-radius: 3px;
-o-border-radius: 3px;
}

.title {
color: #666;
}

.title a:hover {
color: #666;
border-color: #888;
}

.footer {
font-size: .75em;
}

.footer, .footer a {
color: #888;
}


@media only screen and (max-width: 800px) {
    .masonry {
        -moz-column-count: 1;
        -webkit-column-count: 1;
        column-count: 1;
    }
}


@media only screen and (min-width: 800px) {
    .masonry {
        -moz-column-count: 2;
        -webkit-column-count: 2;
        column-count: 2;
    }
}

@media only screen and (min-width: 900px) {
    .masonry {
        -moz-column-count: 2;
        -webkit-column-count: 2;
        column-count: 2;
    }
}

@media only screen and (min-width: 1100px) {
    .masonry {
        -moz-column-count: 2;
        -webkit-column-count: 2;
        column-count: 2;
    }
}

@media only screen and (min-width: 1280px) {
    .wrapper {
        width: 1260px;
    }
}
</style>


<style>
body {
margin: 0;
}
.labs-header a {
text-decoration: none;
display: inline-block;
vertical-align: middle;
padding: 1em 2em;
}
.labs-header,
.labs-header a {
color: rgba(0, 0, 0, .5);
}
.labs-header a:hover {
color: rgba(0, 0, 0, .75);
}
.labs-header.dark,
.labs-header.dark a {
color: rgba(255, 255, 255, .5);
}
.labs-header.dark a:hover {
color: rgba(255, 255, 255, .75);
}
</style>

</head>

<body>
<header class="labs-header">
</header>

<div class="demo-wrap">
<div class="wrapper">
<div class="title"><h1>Responsive CSS Masonry</h1></div>

<div class="masonry">
<div class="item">Hello, this is a really really really really really really really really really really really really really really long sentence.</div>
<div class="item"><iframe width="560" height="315" src="https://www.youtube.com/embed/c5nbLCuiGiU" frameborder="0" allowfullscreen></iframe></div>
<div class="item">Hello!</div>
<div class="item"><img src="http://sites.psu.edu/siowfa14/wp-content/uploads/sites/13467/2014/10/female-red-eyed-tree-frog-tree-frogs-11755689-600-426.jpg"></div>
</div>

</body>

</html>

感谢您的帮助......

1 个答案:

答案 0 :(得分:0)

解决了它。我所要做的就是删除以下代码:

img, iframe {
max-width: 100%;
height: auto;
display: block;
}