I have this script and the problem with it is that I cannot find a way to make the divs that are created to float randomly on the page. They stay in the left corner. Do I need to change the body dimensions or change the position. I guess something is blocking them not to.
One more thing. If someone of you would revise the code and write re-write it following the best practices in JavaScript It will be appreciated!
(function create() {
var docFragment = document.createDocumentFragment();
var count = 5;
var i = 0;
for (i = 0; i < count; i++) {
var numerousDivs = document.createElement("div");
docFragment.appendChild(numerousDivs);
}
document.body.appendChild(docFragment);
var fiveDivs = document.getElementsByTagName("div");
for (i = 0; i < fiveDivs.length; i++) {
div = fiveDivs[i];
alter(div);
moveDivs(div);
}
}());
function moveDivs(div) {
div.style.position = "absolute";
var topPos = parseInt(Math.random() * (maxHeight - 40));
div.style.top = topPos + "px";
var left = parseInt(Math.random() * (maxWidth - 100));
div.style.left + "px";
}
div.style.left + "px";
should be div.style.left = left+"px";
.
div.style.left + "px";
这是一个错字。
div.style.left = left+"px";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.