简体   繁体   English

jQuery .append()与等待渲染

[英]jQuery .append() with wait for render

I'm getting some html from a webservice that I'm appending to a div. 我从要附加到div的Web服务中获取了一些HTML。 This is my success function: 这是我的成功功能:

function SucceededCallback(result) {
  // get the div element
  var RsltElem = $(".placeholder");

  // update div inner Html
  RsltElem.append(result);

  $('.loading-gif').hide();
}

Is there any way I can get .append() not to display until the browser is finished loading and painting it? 有什么方法可以让.append()在浏览器完成加载和绘制之前不显示?

I'd rather not use .append(result).slideDown(n) as n could be anything, depending on what the webservice sends me. 我宁愿不使用.append(result).slideDown(n)因为n可以是任何值,具体取决于网络服务向我发送的内容。

Thanks in advance 提前致谢

Consider using 考虑使用

 $( document ).ready(function() {
        ...
    });

like so: 像这样:

$( document ).ready(function() {
        //get the div element
        var RsltElem = $(".placeholder");

        //update div inner Html
        RsltElem.append(result);


        $('.loading-gif').hide();
});

I don't know what you are painting and when it will complete, so you could also use this: 我不知道你在画什么,什么时候完成,所以你也可以使用这个:

$(window).bind("load", function() {
    // code goes here
});

Code inside the function only runs when the entire page has loaded. 该函数中的代码仅在整个页面加载后才运行。

$(window).on('load', function() {
    //everything is loaded
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM