【问题标题】:Masonry: Images stack vertically, one image each row砌体:图像垂直堆叠,每行一个图像
【发布时间】:2015-01-31 14:05:03
【问题描述】:

我在我的网页中使用 Masonry。问题是页面加载后,所有图像都垂直堆叠,连续一张图像。我希望它们水平和垂直堆叠。见My Jsfiddle.

我在html中使用如下代码:

<div class="container">

        <div id="items">
            <!-- the .box repeats several times -->
            <div class="box panel panel-default">
                <img src="http://placehold.it/200x150/333333/ffffff">
                <div class="panel-body">
                    name:1<br>
                    publisher:2
                </div>
            </div>
        </div>           

</div>

以及以下 javascript 代码:

$(document).ready(function(){     
    var $container = $('#items');

    $container.masonry({
        itemSelector: '.box',
        isFitWidth: true
    });
});

还有 CSS:

.box { margin: 5px; width: 214px; }

.box img { width: 100%; }

.panel .panel-heading {
    color: #ffffff;
    text-align: center;
    margin-right: 0;
    height: 150px
} 

-------- 更新 ---------

上面的代码只是我网页的抽象,在我的第一个版本的小提琴(http://jsfiddle.net/shapeare/saonpswu/)中,我不小心将.box放入了单独的#items,因此,代码不起作用。 @Skelly 指出了这个问题。谢谢,斯凯利。现在小提琴适用于上述演示(http://jsfiddle.net/shapeare/saonpswu/1),但是,我的网页仍然无法工作。现在我在下面的小提琴中放了和我的网页几乎相同的内容:

http://jsfiddle.net/shapeare/saonpswu/2

【问题讨论】:

  • 所以你的一些 jsfiddle 使用 angular.js 而有些则没有。哪一个是您网站的代码不起作用?请澄清您的问题,因为您的问题中根本没有提及角度。

标签: javascript css twitter-bootstrap jquery-masonry masonry


【解决方案1】:

修复您的 HTML,使 id="items" 不存在单独的 DIV

<div id="items">
    <div class="box panel panel-default">
        <img src="http://placehold.it/200x150/333333/ffffff">
        <div class="panel-body">
            name:1<br>
            publisher:2
        </div>
    </div>

    <div class="box panel panel-default">
        <img src="http://placehold.it/200x150/333333/ffffff">
        <div class="panel-body">
            name:1<br>
            publisher:2
        </div>
    </div>

    <div class="box panel panel-default">
        <img src="http://placehold.it/200x150/333333/ffffff">
        <div class="panel-body">
            name:1<br>
            publisher:2
        </div>
    </div>

    <div class="box panel panel-default">
        <img src="http://placehold.it/200x150/333333/ffffff">
        <div class="panel-body">
            name:1<br>
            publisher:2
        </div>
    </div>
</div>

演示:http://bootply.com/OD2uHuKupr

【讨论】:

  • 嗨,谢谢,它解决了演示中的问题。然而,上面的演示只是我网页的抽象,我已经用我实际网页的内容更新了我的小提琴,但它不再起作用了。有什么想法吗?
【解决方案2】:

我忘了提到我正在使用可能导致此问题的 Angular.js。我现在使用来自http://passy.github.io/angular-masonry/ 的指令解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2016-02-10
    相关资源
    最近更新 更多