我有这个
<div class="projekt">
<div id="main" class="home" role="main">
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
</div>
</div>
<div class="projekt">
<div id="main" class="home" role="main">
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
<div class="slide"><img src="http://tribulant.net/lightbox/files/2010/08/image-2.jpg" /></div><div class="slide"><img src="http://cyears.files.wordpress.com/2011/04/image4.jpg" /></div>
</div>
</div>
和jquery:
var accum_width = 0;
$('.home').find('.slide').children('img').each(function() {
accum_width += $(this).width();
});
$('.projekt').width(accum_width);
$('.home').width(accum_width);
如何制作,它将为每个.project分别添加图像的宽度。现在它正在增加页面上所有图像的宽度。
答案 0 :(得分:1)
为每个.projekt(或.home)类分别添加宽度,如下所示:
$('.home').each(function () {
var accum_width = 0;
$(this).find('.slide').children('img').each(function () {
accum_width += $(this).width();
});
$(this).width(accum_width);
});