简体   繁体   English

包装水平布局问题

[英]Packery Horizontal Layout Problems

Hoping that someone out there has some experience with packery, which I'm using for a project. 希望有人在那里有一些经验,我正在用于一个项目。

I cannot get the horizontal layout to work. 我不能让水平布局工作。 Declaring the packery object in HTML seems to work somewhat. 在HTML中声明packery对象似乎有点起作用。

<div class="packery js-packery" data-packery-options='{ "isHorizontal": true }'>
...
</div>

Although it appears that the width and height are not changed through CSS as the documents suggest. 虽然文档显示宽度和高度似乎没有通过CSS改变。 But I've not bothered digging further because I need to use Javascript. 但我没有进一步挖掘,因为我需要使用Javascript。 And the equivalent doesn't seem to work at all: 而等效似乎根本不起作用:

$('.packery').packery({
    itemSelector: '.item',
    isHorizontal: true,
});

This results in the <div> element the packery object was assigned to 0px high and 4px wide. 这导致<div>元素将packery对象分配为0px高和4px宽。 (The 4px width probably comes from some items' 1px border.) The packery docs say that horizontal layout requires setting height. (4px宽度可能来自某些项目的1px边框。) 包装文档说水平布局需要设置高度。 But the CSS provided by the docs seems to do nothing, whether packery was initialized in HTML or Javascript: 但是文档提供的CSS似乎什么都不做,无论是用HTML还是Javascript初始化packery:

/* containers need height set when horizontal */
.packery.horizontal {
    height: 200px;
}

Still, none of my inserted items are visible and the packery <div> is 4px x 0px. 尽管如此,我的插入项目都不可见,而且<div>是4px x 0px。 So, I forced the container's height in Javascript: 所以,我在Javascript中强制容器的高度:

$('.packery').css('height', '400px');

This does increase the element's height but the width remains at four. 这确实增加了元素的高度,但宽度保持为4。 And therefore all the elements are essentially zero width and invisible. 因此,所有元素基本上都是零宽度和不可见的。 So, I tried forcing the container's width: 所以,我尝试强制容器的宽度:

$('.packery').css('width', '1000px');

But this width seems to be ignored. 但这个宽度似乎被忽略了。 I can force the <div> 's width using the element editor in Chrome's developer mode, and that produces some visible, although ugly, content. 我可以使用Chrome开发者模式中的元素编辑器强制<div>的宽度,这会产生一些可见的,虽然丑陋的内容。 But how the hang do I set the <div> 's width in Javascript? 但是如何挂起我在Javascript中设置<div>的宽度? It seems packery is overriding the width I set, whether I do it before or after the call to packery() . 看来packery正在覆盖我设置的宽度,无论是在调用packery()之前还是之后。

Everything in packery seems to work great for vertical layouts. 包装中的所有东西似乎都适用于垂直布局。 But I really want to use the horizontal layout but I'm obviously doing something wrong. 但我真的想要使用水平布局,但我显然做错了什么。 Can anyone help? 有人可以帮忙吗?

I had similar issue with the isHorizontal option. 我有与isHorizo​​ntal选项类似的问题。 I solved it using !important tag in my css on the div width around the packery. 我在我的css中使用!important标签在包装周围的div宽度上解决了它。

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

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