一种简单实用的JS实现页面加载完毕之前loading提示效果,做成js调用即可:
<script type="text/JavaScript"> var pageHeight = document.documentElement.clientHeight, pageWidth = document.documentElement.clientWidth; var loadingTop = pageHeight > 61 ? (pageHeight - 61) / 2 : 0, loadingLeft = pageWidth > 215 ? (pageWidth - 215) / 2 : 0; var loadingHtml = '<div id="loadingDiv" style="position:absolute;left:0;width:100%;height:' + pageHeight + 'px;top:0;background:#f3f8ff;opacity:1;filter:alpha(opacity=80);z-index:10000;"><div style="position: absolute; cursor1: wAIt; left: ' + loadingLeft + 'px; top:' + loadingTop + 'px; width: auto; height: 57px; line-height: 57px; padding-left: 50px; padding-right: 5px; background: #fff url(Image/loading.gif) no-repeat scroll 5px 10px; border: 2px solid #95B8E7; color: #696969; font-family:'Microsoft YaHei';">页面加载中,请等待...</div></div>'; document.documentElement.style.overflowY = 'hidden'; document.write(loadingHtml); document.onreadystatechange = completeLoading; function completeLoading() { if (document.readyState == "complete") { var loadingMask = document.getElementById('loadingDiv'); loadingMask.parentNode.removeChild(loadingMask); document.documentElement.style.overflowY = 'scroll'; } } </script>
说明:
将此段js代码放入head最后即可;
其中loading效果的样式可以根据自己的风格修改,loading.gif图片可自行搜索下载。