0

私はこれを持っています

<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の画像の幅を個別に追加します。これで、ページ上のすべての画像の幅が追加されます。

4

1 に答える 1

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);
});

</ p>

于 2012-07-18T16:05:33.653 に答える