简体   繁体   English

Google+样式图片库

[英]Google+ Style Image Gallery

I'm trying to emmulate the following: 我试图列举以下内容:

在此处输入图片说明

Any ideas how? 有什么想法吗? Basically all photos have the same height and photos are arrange/cropped/resized dynamically to fit perfectly on rows so there are no jagged sides left or right. 基本上所有照片都具有相同的高度,并且照片会动态排列/裁剪/调整大小以完美地适合行,因此左右两侧都不会有锯齿状。 If you resize the browser window it resizes the photos as well to fit. 如果您调整浏览器窗口的大小,它也会调整照片的大小以适合。 I have tried isotope and jquery masonry and neither give me this effect. 我曾经尝试过同位素和jQuery砌体,但都没有给我这种效果。

在这种情况下,流体网格系统将为您提供帮助: http : //twitter.github.com/bootstrap/scaffolding.html#fluidGridSystem

I just implemented this very thing. 我只是实现了这一点。 Here's how I did it: 这是我的操作方式:

  1. When the page loads, I measure the available width of the target container (the container where my images will live), and call this maxWidth 当页面加载时,我测量目标容器(我的图像将在其中生存的容器)的可用宽度,并将其称为maxWidth
  2. I make an AJAX call, passing the maxWidth up to the server 我进行了AJAX调用,将maxWidth传递给服务器
  3. I determine my list of gallery images to display on the server, and process each one by one 我确定要显示在服务器上的画廊图像列表,并逐一处理
  4. During iteration of my list, I keep adding images to a row, the row's length being the maxWidth available (which I passed up). 在列表的迭代过程中,我一直在向行添加图像,该行的长度为可用的maxWidth(我向上传递的)。 Once an image overflows the maxWidth, I calculate the overflow amount 图像溢出maxWidth后,我将计算溢出量
  5. I take that overflow amount, divide it by the number of images in my row, and subtract that value off each of the images in the row (so one image doesn't get its width reduced too much) 我将溢出量除以我行中图像的数量,然后减去该行中每张图像的值(这样一幅图像的宽度不会减小太多)
  6. I repeat this for each row, so each row adds up to exactly maxWidth 我为每一行重复此操作,因此每一行加起来恰好是maxWidth

Some things I had to consider: 我必须考虑的一些事情:

  1. I had to take into account the width of the margins I wanted in between each image, and factor that into the maxWidth accumulated value when processing each row. 我必须考虑到每张图像之间所需的页边距宽度,并在处理每一行时将其作为maxWidth累积值的因素。
  2. We needed a corner stamp image (an image that was larger and was fixed in the top left corner. This image encompassed two rows, and was wider than my other thumbnails. I had to calculate a different maxWidth for the first 2 rows as a consequence. 我们需要一个角标记图像(一个更大的图像,并固定在左上角。该图像包含两行,并且比其他缩略图宽。因此,我必须为前两行计算不同的maxWidth 。
  3. I had to recalculate the dimensions when the browser was resized. 调整浏览器大小时,我不得不重新计算尺寸。 Binding to the resize event of the window caused multiple AJAX calls during dragging. 绑定到窗口的resize事件会导致在拖动过程中调用多个AJAX。 I had to fix the resize event so it only fired when done. 我必须修复resize事件,以便仅在完成后才触发。

Overall, the image gallery turned out quite well. 总体而言,图库的表现非常好。 He's a screenshot. 他是截图。

在此处输入图片说明

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

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