简体   繁体   English

基于容器宽度的图像缩放

[英]Image Scaling Based on Container Width

I'm building an image gallery using Packery, a content packing script in jQuery. 我正在使用Packery构建一个图像库,这是jQuery中的内容打包脚本。

 <script> var $container = $('#content'); // init $container.packery({ itemSelector: '.item', gutter: 10, }); </script> 
 <div id="content"> <div class="item" style="height: 388px; width: 259px;"> <span class="back"></span> </div> </div> 

(Because of some complicated inline styling issues, the images themselves are being displayed as spans of certain size that are styled as having the image as their background.) (由于一些复杂的内联样式问题,图像本身被显示为特定大小的跨度,其风格为将图像作为其背景。)

Currently, because of uniformity of size amongst the images, they pack really nicely in their containing div. 目前,由于图像之间的大小一致,它们在包含div中的包装非常好。 However, when the size of the container changes due to something like a smaller browser window, the packing gets really nasty. 但是,当容器的大小因浏览器窗口较小而发生变化时,包装变得非常糟糕。

What I'd ideally be able to do is have all the images scale down by a certain percent based on what percent of its original size the containing div is (1324px is full size in this case), so that for example, if the container is resized to 1192px, 90% of the original size, all the images resize to 90% as well. 我理想情况下可以做的是将所有图像缩小一定百分比,基于其包含div的原始大小的百分比(在这种情况下为1324px是完整大小),例如,如果容器调整大小为1192px,原始大小的90%,所有图像也调整为90%。

Is there any way to do this using jQuery or CSS? 有没有办法用jQuery或CSS做到这一点?

ElasticCSS can help you do this. ElasticCSS可以帮助您实现这一目标。 It allows you do just that. 它允许你做到这一点。

<div class="unit columns same-height">
    <div class="column">first column content</div>
    <div class="column">second column content</div>
</div>

Imagine that your images are columns, then when the parent gets resized they will all get resized. 想象一下,您的图像是列,然后当父级调整大小时,它们都会被调整大小。 Give it a try. 试试看。

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

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