여기 성공적으로 내가 뭘하려고 오전 않는 바이올린의 2 · 4 루프에 appendChild을 무시 : http://jsfiddle.net/WoofurrBro/qcf4qcm6/2/자바 스크립트는
을 그리고 여기에 작동하지 않습니다 내 설정입니다.
코드를 실행하기 전에
function align() {
var x = document.getElementById('container').offsetWidth;
var y = document.getElementsByClassName('box')[0].offsetWidth;
var z = Math.floor(x/y);
// finds # of columns
for (var i = 0; i < z; i++) {
document.getElementById('container').innerHTML += '<div class=col style="width:' + y + 'px;float:left;"></div>';
};
// creates columns
var columns = document.getElementsByClassName('col');
var boxes = document.getElementsByClassName('box');
// variables for later use
///////////////////////////////////////////////////////////////////////////////
for (var i = 0; i < boxes.length; i++) {
var minIndex;
var column = [];
// minIndex = shortest column, column[] to sort NodeList
for (var iii = 0; iii < columns.length; iii++) {
column[iii] = columns[iii].clientHeight;
};
// converts columns[] (NodeList) to column[] (Array)
column.sort(function (a, b) {
return a - b;
});
// sorts the column[] array
for (var ii = 0; ii < columns.length; ii++) {
if (column[0] == columns[ii].clientHeight) {
minIndex = ii;
break;
};
};
// picks the first item in the column[] array (shortest) and finds the index of it in columns[] NodeList
boxes[i].style.visibility = 'visible';
//ALSO, placing this under the appendChild string causes weird bugs (?)
boxes[i].innerHTML += i + 'h';
columns[minIndex].appendChild(boxes[i]); // !!!!!!!!!!!!!! SEEMS TO IGNORE THIS appendChild
//places them and adds identification
};
///////////////////////////////////////////////////////////////////////////////
};
window.onload = align;
* {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor:default;
margin:0px;
padding:0px;
}
html {
background-color:#20293F;
}
#title {
text-align:center;
padding-top:40px;
font-size:60px;
margin-bottom:10px;
}
#description {
font-size:14px;
text-align:center;
margin:0 auto 30px auto;
max-width:450px;
}
.box {
width:250px;
word-wrap:break-word;
background-color:rgba(0, 0, 0, 0.30);
margin:10px 0 10px 0;
}
col {
margin:0 10px 0 10px;
}
#containerwrap {
background-color:rgba(0, 0, 0, 0.30);
min-width:800px;
width:100%;
}
#container {
overflow:hidden;
width:800px;
margin:0 auto;
}
.postTitle {
text-align:center;
font-size:30px;
color:#5F70A6;
}
.postBody {
padding:10px;
font-size:12px;
color:#5F70A6;
}
<div id="containerwrap">
<div id="container">
<div class="box">
<h2 class="postTitle">11 boots</h2>
<div class="postBody">
<p>11 bbooots</p>
</div>
</div>
<div class="box">
<h2 class="postTitle"></h2>
<div class="postBody">
<p>22 sweg</p>
</div>
</div>
<div class="box">
<h2 class="postTitle"></h2>
<div class="postBody">
<p><span></span><span></span><span>33 thisisadivthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimetocopythisshitsorries<span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span><span>divthingwithoutanyspanssodontevenexpectthehtmltogeneratespanslikeitdidlasttimebitchtimeto</span></span>
</p>
</div>
</div>
<div class="box">
<h2 class="postTitle">44 ether</h2>
<div class="postBody">
<p>44 infinite, silk-smooth darkness covers your eyes as you float in the skies
<br>lightning bolts of pleasure and happiness strike you, through your senses, as each rain drop pops silently on your skin
<br>the windy silence cloak guards your peace as you rest in the sky, floating upwards and feeling the rain drops pop and the air flowing around you with kind love, giving you calmness and calmness again
<br>this sea of magic around you might not be, but does it matter, if that’s what’s on your mind. you let it stay and you float, you float away, as you let it be
<br>and it strikes you that you are where your mind is and your mind is here, here in this magic place, as the raindrops pop lightning on your skin, you allow it to be, might you never leave, but if you ever left, might you come back to be here once more
<br>just close your eyes</p>
</div>
</div>
</div>
</div>
그러나 두 개의 상자 만 열에 배치됩니다. 22 개와 44 개의 상자는 완전히 무시되며 이유는 모르겠습니다.
제대로 작동하려면 어떻게해야합니까?
우리는 그 코드가 무엇을해야하는지 알지 못합니다. 예상 결과를 (a), (b) 실제 결과와 비교하여 알려주십시오. 두 번째와 네 번째 루프에 대한'appendChild'를 무시한다고 알려주는 정보가 충분하지 않습니다. (그리고 참고로'for' 루프와'if' 문의 닫는 중괄호 뒤에 세미콜론이 필요하지 않습니다.) – JLRishe
@JLRishe 열 높이에 따라 열로 상자를 정렬해야하므로 가장 짧은 열을 먼저 채 웁니다 . 바이올린은 이것을 완벽하게 보여줍니다. 이것이 그들에 숫자가있는 이유입니다. – Roberts
좋아, 그럼 제대로 작동한다면 어떻게 될까? 박스 11, 22, 33 및 44는 어떻게 배열되어야합니까? 바이올린의 상자는 tumblr 페이지의 박스와 크게 다릅니다. – JLRishe