我正在使用javascript,CSS和HTML通過使用for循環遍歷屏幕寬度和高度以16X16的間隔來繪製屏幕。下面是我的循環目前的樣子:在HTML5中繪製最快的方式是什麼?
{
div = document.getElementById('mainView');
while (div.children.length > 0)
div.removeChild(div.children[0]);
for (y = this.y; y < this.y + this.height; ++y)
{
for (x = this.x; x < this.x + this.width; ++x)
{
toAppend = document.createElement('div');
viewCoords = this.convertWorldToView(x, y);
toAppend.style.top = viewCoords[1] * 16 + 'px';
toAppend.style.left = viewCoords[0] * 16 + 'px';
mainViewDiv.appendChild(toAppend);
if (fullMap[y][x] == TILE_WATER)
{
startTile = Math.round(Math.random() * 3) + 1;
toAppend.className = "Water" + startTile + "Tile";
}
else
{
toAppend.className = typeClassDecoder[fullMap[y][x]];
}
}
}
}
有提請所有這些瓷磚使用或者帆布或某些功能的JavaScript或JavaScript和CSS混合畫面更快的方法?
如果我得到它正確地要刪除其所有內容後添加的div在平鋪方式。 –
沒有完整的代碼,沒有標記/ css,很難理解發生了什麼。我建議你把你的代碼放在jsfiddle(http://jsfiddle.net/)中並提供鏈接。 –
在jsfiddle上的類似任務的例子在這裏:http://jsfiddle.net/robhawkes/cV3Rr/ –