下面的代碼的cernain數一個div:廣場後的圖像
var images = [/*array with images*/];
var nofImages = images.length;
$(document).ready(function(){
var docheight = $('.main_insidem').height();
var docwidth = $('.main_insidem').width();
var he = Math.round((docheight/120));
var wi = Math.round((docwidth/115));
var total = (he*wi);
var container = document.getElementById('slidesContainer');
for (var i=0;i<nofImages;i++) {
var slide = document.createElement('div');
slide.className="slide";
var img = document.createElement('img');
img.src=images[i];
img.className="image"+i;
slide.appendChild(img);
container.appendChild(slide);
}
})
表演:
<div class='main_insidem' style="height:500px;">
<div id="slidesContainer">
<div class="slide"><img src="1.png" class="image0"></div>
<div class="slide"><img src="2.png" class="image1"></div>
<div class="slide"><img src="3.png" class="image2"></div>
<div class="slide"><img src="4.png" class="image3"></div>
.
.
.
.
</div>
</div>
但我需要:
<div class='main_insidem' style="height:500px;">
<div id="slidesContainer">
<div class="slide"><img src="1.png" class="image0"> <img src="2.png" class="image1">.. and and so on until the value in var total is reached</div>
<div class="slide"><img src="..png" class="image.."> <img src="...png" class="image">.. and and so on until the value in var nofImages is reached</div>
.
.
.
.
</div>
</div>
我怎麼能這樣做?
非常感謝
我不喜歡不明白你在var total_中的圖片數量 - 你能更具體地表達你想要達到的目標嗎? – Chris 2011-03-31 12:05:26
您是否希望div與容器位於同一水平或嵌套? – McStretch 2011-03-31 12:05:37
聽起來像你想在主循環內的另一個循環。有人會回來,並給你的解決方案,因爲沒有人在這裏讓人們學習...... – epascarello 2011-03-31 12:07:17