append2 給append 新增回撥方法

王大溼發表於2014-08-22
   $.fn.append2 = function(html, callback) {
        var originalHtmlLength = $("body").html().length;
        this.append(html);
        var nums = 1;
        var timer1 = setInterval(function() {
            nums++;
            var clearIntervalfun = function() {
                clearInterval(timer1)
                callback();
            } 
            var flag = originalHtmlLength != $("body").html().length || nums > 1000;
            // console.info("append html expend {0}ms".format(nums))
            flag && clearIntervalfun()

        }, 1)
    };

 

相關文章