简体   繁体   English

处理诸如布局/加载之类的可变图像大小

[英]Dealing with variable image sizes in a pinterest like layout/load

I am trying to compile a pinterest style layout for my site. 我正在尝试为我的网站编译pinterest样式布局。 And have accomplished it, other then the load times. 并完成了此任务,除了加载时间。 I have set about to get the load of my site as fast as possible. 我已经准备好尽快获取网站的负载。

To do so, I have come across the lazy load script (as can be found here: http://www.appelsiini.net/projects/lazyload ) which essentially loads the site first, and then the images, thus speeding up the usability of the site on load, similar to what pinterest does.. 为此,我遇到了延迟加载脚本(可以在这里找到: http : //www.appelsiini.net/projects/lazyload ),该脚本实际上首先加载了站点,然后加载了图像,从而加快了可用性。网站的负载情况,与pinterest相似。

The issue I have been having is, while the script works, because we have a box around each image to style and present it, and undefined sizes on the images, the layout comes out all messed up every time. 我遇到的问题是,尽管脚本起作用了,因为我们在每个图像周围都有一个框来设置样式并显示它,并且图像上的尺寸没有定义,因此布局每次都变得混乱。 Essentially, the image sizes are always surprising the layout once they load. 本质上,一旦加载图像大小,布局总是令人惊讶。

What is the best way about going about fixing this problem? 解决此问题的最佳方法是什么? What does pinterest do? pinterest是做什么的? Similar to them, we have images of all shapes and sizes, that will be added dynamically to our site by users via both php and javascript, so simply figuring out all the sizes of each image ourselves is not something we can do. 与它们类似,我们拥有各种形状和尺寸的图像,用户将通过php和javascript将它们动态添加到我们的网站中,因此,简单地自己弄清楚每个图像的所有尺寸是我们不能做的。

Thanks for your help! 谢谢你的帮助!

Pinterest most likely has measured the images and stored the image dimensions in there database. Pinterest最有可能已测量图像并将图像尺寸存储在该数据库中。 Then simply output the height within the img tag, width is not dynamic as its set by CSS 然后只需在img标签内输出高度,宽度就不会像CSS设置的那样动态

First a set rule in css controls the width of the image (this wont change): 首先,css中的一个设置规则控制着图像的宽度(这不会改变):

.pin .ImgLink img
{
  max-width: 192px;
  opacity: 1;
}

.PinImageImg
{
  min-height:75px;
  background-color:#f2f0f0
}

and then the HTML markup of each img tag controls the height (this changes for each image): 然后每个img标签的HTML标记控制高度(每个图像都会改变):

<img src="http://media-cache-ec5.pinterest.com/upload/177118197817236677_8RujApQy_b.jpg" alt="Moon Goddess Gown by Halston Heritage" data-componentType="MODAL_PIN" class="PinImageImg" style="height: 288px;" />

This way there is no popping of layout as each image is loaded by javascript. 这样,由于每个图像均由javascript加载,因此不会弹出布局。

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

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