我在下面有这个脚本,即使滚动条已被移动,页面偏移也会保持空白。请帮忙
<script>
var menu, yPos;
function yScroll(){
menu = document.getElementById('Menu');
menu = document.getElementById('cpBtn');
yPos = document.pageYOffset;
if(yPos > 150)
{
menu.style.position="fixed";
menu.style.top="0px";
}
else
{
menu.style.position="relative";
menu.style.background="red";
}
alert(yPos);
}
document.addEventListener("scroll", yScroll);
</script>