Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery resize of images
    primarykey
    data
    text
    <p>I have managed to fit automatically the images of the gallery per row depending if it´s horizontal (one image per row) or vertical (two images per row).</p> <p>The problem now is that I want the images to be scalable (resize on window resize) but I have no idea how to achieve it. How it should me made? <strong>(I'm looking for a javascript/jquery solution to avoid height: auto problems...)</strong></p> <p>This is the web: <a href="http://ldlocal.web44.net/test2/gallery.html" rel="nofollow">http://ldlocal.web44.net/test2/gallery.html</a></p> <p>Can be downloaded here: <a href="http://ldlocal.web44.net/test2/test.zip" rel="nofollow">http://ldlocal.web44.net/test2/test.zip</a> </p> <p>this is my code:</p> <pre><code>var gallery = new Gallery($('#gallery_images_inner')); function Gallery(selector){ this.add_module = function(type, image){ var container = $('&lt;div /&gt;' , { 'class' : 'gallery_container' }).append(image); if(type == 'horizontal'){ var h_ar = image.attr('height') / image.attr('width'); container.css({ 'width' : selector.width(), 'height' : selector.width()*h_ar }) } if(type == 'vertical'){ container.css({ 'width' : v_width, 'height' : v_height }) } container.appendTo(selector); container.children('img').fitToBox(); } var _this = this; var gutter = 0; // start vars for counting on vertical images var v_counter = 0; var w_pxls = 0; var h_pxls = 0; // iterates through images looking for verticals selector.children('img').each(function(){ if($(this).attr('width') &lt; $(this).attr('height')){ v_counter++; h_pxls += $(this).attr('height'); w_pxls += $(this).attr('width'); } }) // calculates average ar for vertical images (anything outside from aspect ratio will be croped) var h_avrg = Math.floor(h_pxls/v_counter); var w_avrg = Math.floor(w_pxls/v_counter); var v_ar = h_avrg/w_avrg; var v_width = (selector.width())/2; var v_height = v_width*v_ar; selector.children('img').each(function(){ if(parseInt($(this).attr('width')) &gt; parseInt($(this).attr('height'))){ _this.add_module('horizontal', $(this)); }else{ _this.add_module('vertical', $(this)); } }) selector.isotope({ masonry: { columnWidth: selector.width() / 2 } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload