1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
//resize les image dans un bloc images
function sizeImgBlock (imagescolection) {
imgs = $(imagescolection).find('img');
$(imgs).removeAttr('style');
$(imgs).removeAttr('width');
$(imgs).removeAttr('height');
nbimg = $(imgs).length;
trace ('-------sizeImgBlock------------');
trace(imgs);
trace(nbimg);
maxw = $(imagescolection).width();
trace('maxw=' + maxw); //largeur de ma div containeur
grandeHauteur = 0;
LargeurTotale = 0;
total_ratio = 0;
$.each(imgs, function (index, value) {
trace ($(this));
src = $(this).attr('src');
//on cherche l'image la plus large
//w = parseInt($(this).width());
//h = parseInt($(this).height());
w = getImgWidth(src);
h = getImgHeight(src);
trace ('w='+w);
trace ('h='+h);
if (h > grandeHauteur) {
grandeHauteur = h ;
}
});
trace ('grandeHauteur='+grandeHauteur);
//j'ai la grande heuteur, je resize les images à cette hauteur pour calculer la largeur totale
$.each(imgs, function (index, value) {
trace ('--boucle largeur totale--');
trace ($(this));
ih = $(this).height();
iw = $(this).width();
trace ('ih='+ih);
trace ('iw='+iw);
//$(this).width( ($(this).width() * ( ih / grandeHauteur) ) );
ratiolocalh = ih / grandeHauteur ;
trace ('ratiolocalh='+ratiolocalh);
trace ('largeur de cette image si agrandie pour avoir la taille de la plus haute');
largagr = iw / ratiolocalh;
//on resize ;
$(this).width(largagr);
$(this).height(grandeHauteur);
trace ( largagr );
//largeur totale de la bande d'images si elles avaient toutes la hauteur de la plus haute
LargeurTotale = LargeurTotale + largagr;
});
trace ('LargeurTotale='+LargeurTotale);
//ratio entre la largeur maximale et la largeur totale de la bande d'images
ratioLargeurs = maxw / LargeurTotale ;
trace ('ratioLargeurs='+ratioLargeurs);
//on resize toutes les images en foncion du ratio largeur
$.each(imgs, function (index, value) {
trace ('--boucle resize final--');
trace ($(this));
iw = $(this).width() ;
ih = $(this).height() ;
nextw = iw * ratioLargeurs ;
nexth = ih * ratioLargeurs ; //grandeHauteur * ratioLargeurs
trace ('iw='+iw);
trace ('nextw='+nextw);
trace ('nexth='+nexth);
$(this).attr( 'width','' ) ;
$(this).attr( 'height','' ) ;
//je lève 5 px de marge
$(this).css('width', parseInt(nextw) -5 ) ;
$(this).css('height', parseInt( nexth) -5 ) ;
});
$(imagescolection).css('height', $(imagescolection).find('img').height());
} |
Partager