Long task in Javascript
Posted
by Misha Moroshko
on Stack Overflow
See other posts from Stack Overflow
or by Misha Moroshko
Published on 2010-05-22T13:18:00Z
Indexed on
2010/05/22
13:20 UTC
Read the original article
Hit count: 194
Why in the following code I see the whole page at once ? Thanks !
HTML:
<div></div>
CSS:
div {
width: 100px;
height: 300px;
border: 1px solid black;
text-align: center;
}
Javascript:
$(function() {
for (var i=0; i<15; i++) {
sleep(100);
$("div").append("<span>--- " + i + " ---<br /></span>");
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
});
© Stack Overflow or respective owner