插入DOM时IE冻结GIF动画

IE freezes GIF animation when DOM insert

本文关键字:GIF 动画 冻结 IE DOM 插入      更新时间:2023-09-26

我的代码有一个动画GIF(加载图像)

我从Ajax调用中获得变量"data"中的html页面。

$("#content").html(data); // takes about 5 seconds and the GIF animation freezes since IE is single threaded.

是否有一种方法可以使用setTimeout/setInterval函数逐行写入数据,以便短暂释放线程,以便动画继续

Fiddle URL: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>

我在为我的一个项目添加"加载"指示符时遇到了这个问题。我用这个解决了我的问题。因为它不是图像,所以它不会冻结。