我的代码有动画GIF(加载图片)
我从Ajax调用中获取变量“data”中的html页面。
$("#content").html(data); // takes about 5 seconds and the GIF animation freezes since IE is single threaded.
有没有办法用setTimeout / setInterval函数逐行写入数据,以便线程被释放一小段时间以便动画继续?
小提琴网址: http://jsfiddle.net/deepakssn/Kp2bM/
我尝试过替代解决方案:
<style>
#loading {
background: url(loading.gif) no-repeat center center #fff;
display: block;
position: fixed;
height: 500px;
width: 500px;
}
</style>
<script src="../scripts/jquery.js"></script>
<script>
$(window).load(function () {
function writeData(data) {
var yourLines = data.split("\n");
for (var i = 0, j = yourLines.length; i < j; i++) {
var x = setTimeout(function() {
$("#content").append(yourLines[i]);
console.log("Line No :"+[i]+" "+Date.now());
}, 5000);
}
}
function ajaxLoad() {
$.ajax({
url: "test.txt"
}).done(function (data) {
console.log("success"+Date.now());
writeData(data);
//$("#content").html(data);
console.log("loaded data"+Date.now());
});
}
ajaxLoad();
});
</script>
<div id="loading"></div>
<div id="content"></div>