js实现固钉效果
先添加样式
<style>
.Affix {
position: fixed;
top: 0;
left: 0;
}
</style>
监听滚动和页面距离
const oAffix = document.getElementById("navigator");
const offsetT = oAffix.offsetTop;
window.onscroll = function () {
const scrollH =
document.documentElement.scrollTop || document.body.scrollTop;
scrollH >= offsetT
? (oAffix.className = "Affix")
: (oAffix.className = "");
};