【发布时间】:2016-01-26 13:09:04
【问题描述】:
当动态更改 div 中的内容时,是否有办法延迟新内容的显示,直到所有布局完成?
我正在使用 javascript 和 ajax 更新 div 的内容,当我插入 ajax 脚本返回的 html 时,它似乎在元素可见后进行新内容的布局,溢出目标 div
虽然这发生得很快并且最终结果完全符合我的期望,但它确实会产生令人不快的“闪烁”,我想避免这种情况
javascript
$requestURL = 'Scripts/getCategoryItems.php?Category='+$category+'&PageLength='+$pageLength+'&Page='+$page ;
AjaxRequest.open('GET',$requestURL,true);
AjaxRequest.onreadystatechange = function()
{ if(AjaxRequest.readyState == 4)
{
if (AjaxRequest.responseText !== 'false')
{ TargetContainer.style.display = "none";
TargetContainer.innerHTML=AjaxRequest.responseText;
TargetContainer.style.display = "block";
} else { alert(AjaxRequest.responseText); } ;
document.body.className = '';
}
};
document.body.className = 'waiting';
AjaxRequest.send();
HTML:
<div id="Content" style="float:left; width:820px; height:550px; max-height:550px; color:#E0E0E0; padding-top:30px; overflow:hidden;"></div>
【问题讨论】:
-
请将您的代码添加到问题中。
标签: javascript html ajax dom