Html 如何防止徽标在使用时引起导航栏抖动';s装载
我一直在寻找一个解决办法,但似乎没有一个奏效 我遇到的问题发生在导航到网站上的任何和所有页面时——这非常烦人 虽然我希望加载站点图像需要时间,但这种加载会影响我的导航栏和站点徽标的加载。在加载每个页面所需的时间内,我的站点的徽标完全不存在——这导致我的导航栏一直向上移动,直到徽标出现。这通常需要一瞬间,但也完全取决于用户的互联网连接) 如何防止这种情况发生?这会导致我的整个网站在导航时“反弹”,所有内容都会在没有徽标的情况下短暂上移Html 如何防止徽标在使用时引起导航栏抖动';s装载,html,css,navbar,loading,image-loading,Html,Css,Navbar,Loading,Image Loading,我一直在寻找一个解决办法,但似乎没有一个奏效 我遇到的问题发生在导航到网站上的任何和所有页面时——这非常烦人 虽然我希望加载站点图像需要时间,但这种加载会影响我的导航栏和站点徽标的加载。在加载每个页面所需的时间内,我的站点的徽标完全不存在——这导致我的导航栏一直向上移动,直到徽标出现。这通常需要一瞬间,但也完全取决于用户的互联网连接) 如何防止这种情况发生?这会导致我的整个网站在导航时“反弹”,所有内容都会在没有徽标的情况下短暂上移 为图像标签指定绝对高度属性。这将使浏览器保持img标记应有的
为图像标签指定绝对高度属性。这将使浏览器保持img标记应有的高度,并允许元素加载到正确的位置。您也可以尝试调整加载程序,使其仅在页面中的所有元素都已加载时加载页面。像这样简单的事情:
<!DOCTYPE html>
<html>
<head>
<style>
/* Center the loader */
#loader {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
@-webkit-keyframes animatebottom {
from { bottom:-100px; opacity:0 }
to { bottom:0px; opacity:1 }
}
@keyframes animatebottom {
from{ bottom:-100px; opacity:0 }
to{ bottom:0; opacity:1 }
}
#myDiv {
display: none;
text-align: center;
}
</style>
</head>
<body onload="myFunction()" style="margin:0;">
<div id="loader"></div>
<div style="display:none;" id="myDiv" class="animate-bottom">
<h2>Tada!</h2>
<p>Some text in my newly loaded page..</p>
</div>
<script>
var myVar;
function myFunction() {
myVar = setTimeout(showPage, 3000);
}
function showPage() {
document.getElementById("loader").style.display = "none";
document.getElementById("myDiv").style.display = "block";
}
</script>
</body>
</html>
/*使装载机居中*/
#装载机{
位置:绝对位置;
左:50%;
最高:50%;
z指数:1;
宽度:150px;
高度:150像素;
利润率:-75px 0-75px;
边框:16px实心#F3;
边界半径:50%;
边框顶部:16px实心#3498db;
宽度:120px;
高度:120px;
-webkit动画:旋转2s线性无限;
动画:旋转2s线性无限;
}
@-webkit关键帧旋转{
0%{-webkit变换:旋转(0度);}
100%{-webkit变换:旋转(360度);}
}
@关键帧旋转{
0%{变换:旋转(0度);}
100%{变换:旋转(360度);}
}
/*将动画添加到“页面内容”*/
.制作底部动画{
位置:相对位置;
-webkit动画名称:animatebottom;
-webkit动画持续时间:1s;
动画名称:animatebottom;
动画持续时间:1s
}
@-webkit关键帧animatebottom{
从{底部:-100px;不透明度:0}
至{底部:0px;不透明度:1}
}
@关键帧动画块{
从{底部:-100px;不透明度:0}
到{底部:0;不透明度:1}
}
#myDiv{
显示:无;
文本对齐:居中;
}
塔达!
我新加载的页面中的某些文本
var-myVar;
函数myFunction(){
myVar=setTimeout(showPage,3000);
}
函数showPage(){
document.getElementById(“加载器”).style.display=“无”;
document.getElementById(“myDiv”).style.display=“block”;
}
经过一些修改,可以帮助用户体验UI
资料来源:
希望有帮助 1-使用预加载程序/2-延迟加载图像/3-确保图像是渐进式JPEG(我建议将2和3结合使用)