
var fixed = document.getElementById("fixed")
var ptin = document.getElementById("ptin")
var diyfastposttop = document.getElementById("diyfastposttop")
var offs = fixed.offsetTop
var offs1 = ptin.offsetTop
var fixedHeight = fixed.clientHeight
var diyfastposttopOffs = diyfastposttop.offsetTop
function scrollLis() {
var t = document.documentElement.scrollTop || document.body.scrollTop
localStorage.setItem("t", "" + t)
if (t >= offs) {
fixed.classList.add("fixed")
if (diyfastposttopOffs <= t + fixedHeight) {
fixed.style.top = diyfastposttopOffs - t - fixedHeight + "px"
} else {
fixed.style.top = ""
}
} else {
fixed.classList.remove("fixed")
}
if (t >= offs1) {
toptb.classList.add("jtb")
} else {
toptb.classList.remove("jtb")
}
}
window.onscroll = function () {
scrollLis()
}
window.scrollTo({
top: Number(localStorage.getItem("t")),
behavior: "smooth",
})
请采纳
检查是否引入了jquery.js
检查选择器是否正确;
检查样式名是否正确;
注意选择器的定位是否准确。
addClass语法:
$("选择器").addClass("样式名");
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)