1
すべての画像の合計幅と最後の画像の幅をコンテナdivにする必要があります。私はこれを使って結合画像の幅を得ました:すべての要素の幅+最後の要素の幅
$(window).load(function() {
$('.pressimage').each(function() {
var totalImageWidth = 0;
$("img", this).each(function() {
totalImageWidth += $(this).width();
});
$(this).width(totalImageWidth);
});
});
最後の画像の幅をどのように追加できますか?アイブ氏はこれを試してみましたが、それは動作しません:
$(window).load(function() {
$('.pressimage').each(function() {
var totalImageWidth = 0;
$("img", this).each(function() {
totalImageWidth += $(this).width();
});
$("img", this).last(function() {
lastImageWidth = $(this).width();
});
$(this).width(totalImageWidth + lastImageWidth);
});
});
おかげ
UPDATE。 申し訳ありませんが、間違ったコードを作成していました。
$(window).load(function() {
var pub_accum_width = 0;
$('.view-public-collection .pubimagecolor').find('img').each(function() {
pub_accum_width += $(this).width();
});
//alert(pub_accum_width);
$('.view-public-collection .view-content').width(pub_accum_width);
});
そしてここでは、私の修正コードがあるが、それはdivの任意の幅広に形成されていません:
$(window).load(function() {
var pub_accum_width = 0;
var pub_accum_last = 0;
$('.view-public-collection .pubimagecolor').find('img').each(function() {
pub_accum_width += $(this).width();
});
$('.view-public-collection .pubimagecolor').find('img').last(function() {
pub_last_width += $(this).width();
});
$('.view-public-collection .view-content').width(pub_accum_width + pub_last_width);
});
おかげ
ここで私は、そのすべての画像のdivの幅作るているものです
申し訳ありませんが、私は間違ったコードを投稿しました。これらのコメントに実際にコードを投稿できないので、私のメインポストを更新しました。ありがとうございました – Evans
Working great。ありがとう – Evans
私の最初のコードセクションでも、同じ方法でlast()を使う必要があります。 – Evans