简体   繁体   English

使用替换子项时HTML div内容的闪烁显示

[英]Flashing display of html div content when using replace child

I have a div with some picture and text, it has variable length. 我有一些图片和文字的div,它的长度可变。 I load its content from server and using javascript function (replaceChild) to change this content. 我从服务器加载其内容,并使用javascript函数(replaceChild)更改此内容。 Everything (about functionality and performance) is ok but it always flashes? 一切(关于功能和性能)都可以,但是它总是闪烁吗? How do i resolve it? 我该如何解决?

html html

<div class="container">
    <div class="main">
        <!-- some text and img tag in HERE -->
    </div>
</div>

javascipt javascipt

container.element.replaceChild(main.element, old_main.element);

I think it's the expected behaviour, based on what you have done. 我认为这是预期的行为,具体取决于您所做的工作。

You could try to use: 您可以尝试使用:

Plain Javascript: 纯Javascript:

document.getElementById("main").appendChild(newContent);

jQuery: jQuery的:

$("#main").append(newContent);

newContent can be HTML and it assumes it has an id. newContent可以是HTML,并假定它具有ID。

Hope this helps. 希望这可以帮助。

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

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