0

高さのみが設定された画像のセット(ギャラリー)があるimg: height:200px;ため、すべての画像の高さは同じですが幅が異なり、すべての画像の幅を取得する必要があります。

それは可能ですか?

現在私が使用しているもの:

var accum_width = 0;
$('.scroll-content-item img').each(function() {
accum_width += $(this).width() + 20;
});
alert(accum_width);

$( ".scroll-content" ).css('width', accum_width);

しかし、私は100(マージン)を取得しています。何か案は?

ありがとうございました

4

4 に答える 4

1

それぞれを使用して、imgタグを反復処理します

$('img').each(function(){
   alert(this.width);  
})

画像に共通のクラスがある場合は、クラスセレクターを使用します。

$('img.classname').each(function(
   alert(this.width);  //with javascript
   alert($(this).width());  //with jQuery
})
于 2012-12-06T15:37:43.420 に答える
1

説明の後

$(window).load(function(){
    var widthSum = 0;
    $('img').each(function(){
       widthSum += this.width;
    });
    // do something with the widthSum here..
});

を使用し$(window).loadて、画像が読み込まれていることを確認します。

于 2012-12-06T15:39:37.820 に答える
1

幅関数を確認することをお勧めします:http://api.jquery.com/width/

$('img').width();
于 2012-12-06T15:41:06.867 に答える
0

以下をお試しください

var widthcoll = $.each(imagecollection,function(){
return $(this).width();
});

ありがとう

于 2012-12-06T15:37:51.063 に答える