导航条position变换

document.addEventListener('scroll', function (event) {
var scrollDistance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
if (scrollDistance >= 200) { // 触发的位置
document.getElementsByClassName('nav')[0].style.cssText = 'position:fixed;top:0px;';} else {
document.getElementsByClassName('nav')[0].style.cssText = 'position:relative;';
}
});

posted @ 2020-05-30 01:33  A-zero  阅读(112)  评论(0编辑  收藏  举报