これはどのように機能しますか:
newDiv.style.top = topBar.style.height.split("px")[0]+"px";
->>><div style="top: 30.31px;" class="lineSeparator"></div>
そして、これも機能します
newDiv.style.top = topBar.style.height.split("px")[0]-2+"px";
->>><div style="top: 28.31px;" class="lineSeparator"></div>
そして、これも機能します
newDiv.style.top = topBar.style.height.split("px")[0]/2+"px";
->>><div style="top: 15.15px;" class="lineSeparator"></div>
しかし、これは機能しません:
newDiv.style.top = topBar.style.height.split("px")[0]+2+"px";
->>><div style="top: 30.31px;" class="lineSeparator"></div>
私も試しました:
newDiv.style.top = (topBar.style.height.split("px")[0]+2)+"px";
これは私の完全なコードです:
function generateSeparators(n){
for(var i=0;i<n;i++){
var newDiv=document.createElement("div");
newDiv.style.top = topBar.style.height.split("px")[0]+"px";
newDiv.className = "lineSeparator";
sideBar.appendChild(newDiv);
}
}