我有一个脚本,它将div data-role="content"></div>
的高度调整为窗口的高度,减去页脚和页眉的高度。一切都正常运行,但是当一个页面通过AJAX加载到DOM中,我得到一点点的闪烁,而内容区域的高度设置增强JavaScript执行速度更快
<script>
(function() {
var fixgeometry = function() {
/* Some orientation changes leave the scroll position at something
* that isn't 0,0. This is annoying for user experience. */
scroll(0, 0);
/* Calculate the geometry that our content area should take */
var header = $(".ui-header:visible");
var footer = $(".ui-footer:visible");
var content = $(".ui-content:visible");
var viewport_height = $(window).height();
var content_height = viewport_height - header.outerHeight() - footer.outerHeight();
/* Trim margin/border/padding height */
content_height -= (content.outerHeight() - content.height());
content.height(content_height);
}; /* fixgeometry */
$(document).ready(function() {
$(window).bind("orientationchange resize pageshow", fixgeometry);
});
})();
</script>
它真的noticible当其在移动设备上进行测试,它引起了我的图像,基于百分比,需要片刻,然后在脚本运行后进行调整。这里是jsFiddle
的链接有无论如何优化这个脚本,以便闪烁的效果消失了吗?
谢谢,我之前看到过这篇文章,但并不适用于我的情况。看到JSfiddle明确表明它会有所帮助。 – mhartington