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);
});
감사
을 업데이트] 질문에 대한
죄송합니다. 잘못된 코드를 게시했습니다. 필자는 이러한 의견에 코드를 게시 할 수 없으므로 필자의 주요 게시물을 업데이트했습니다. 감사합니다 – Evans
Working great. Thanks – Evans
코드의 첫 번째 섹션에서도 last()와 같은 방식으로 사용해야합니다. – Evans