Hello everyone, I"m going to create a top navigation because for some reason I have to use absolute positioning. But when the scroll bar goes down, the navigation bar will flash very tired. The code is as follows:
< html >
< head >
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<style>
body, html {
padding:0;
margin: 0;
width: 100%;
height: 100%;
position: relative;
}
-sharptop {
position: absolute;
left:0;
top:0;
height: 20px;
width: 100%;
background-color: red;
}
-sharpbody {
width: 100%;
height: 150%;
background-color: yellow;
}
</style>
< / head >
< body >
< div id= "top" > < / div >
< div id= "body" > < / div >
< / body >
< script >
var doc = document;
var Dtop = doc.getElementById ("top");
var dBody = doc.getElementById (" body");
function getScrollTop () {
var scrollTop=0;
if(document.documentElement&&document.documentElement.scrollTop)
{
scrollTop=document.documentElement.scrollTop;
}
else if(document.body)
{
scrollTop=document.body.scrollTop;
}
return scrollTop;
}
window.addEventListener ("scroll", function (e) {
)var e = window.event || e;
var scrollTop = getScrollTop();
Dtop.style.top = scrollTop + "px"
})
< / script >
< / html >
find a solution, thank you