I’m using DOM to operate on the pages depending on the backend JSON data, say, some tables on the page may have 10-50 rows of the data, during the time, i saw the page shakes a lot, looks not nice to the users,
is there any good way to deal with this?
something codes to demo the effect is like this… i’ve a table in the middle, with an unknown size…
test
window.onload = function(){
setTimeout(createTable, 3000);
}
function createTable(){
var table = document.createElement("table");
for(var i = 0; i < 10; ++i){
var tr = document.createElement("tr");
var td = document.createElement("td");
td.innerHTML = "row " + i;
tr.appendChild(td);
table.appendChild(tr);
}
document.getElementById("tablewrapper").appendChild(table);
}
</script>
</head>
<body>
<div style="width:300px; background-color:blue;">
hello
</div>
<div id="tablewrapper">
</div>
<div style="width:300px;background-color:red">
world
</div>
</body>
Usually you should put a loading mask on top of it so the user can’t see the shaking.
In most frameworks there are utility functions like described here for ExtJS or as plugin for jQuery but you can easily do it on your own (just a div on top of your area or the whole page, hide the div when your code is done).