标签:scroll ons false function bre name for lis text
var hs = $(".cnblogs-markdown h2,.cnblogs-markdown h3,.cnblogs-markdown h4");
if (hs.length) {
addList()
}
function addList() {
$("body").append($('<div id="hlist"></div>'));
hs.each(function (i, v) {
var txt = $(this).text();
var idd = v.localName + i;
v.id = idd;
var item = $("<a></a>");
item.text(txt);
item.attr("href", ("#" + idd));
$("#hlist").append(item)
})
}
window.onscroll = function () {
var nowTop = window.scrollY;
nowTop < 600 ? $('a[href="#top"]').hide() : $('a[href="#top"]').show();
if (!hs.length) {
return false
}
$("#hlist>.active").removeClass();
for (var k = 0; k < hs.length; k++) {
if (nowTop < hs[k].offsetTop) {
break
}
}
if (k !== 0) {
$("#hlist>a")[k - 1].setAttribute("class", "active")
} else {
return false
}
};
标签:scroll ons false function bre name for lis text
原文地址:https://www.cnblogs.com/ak-b/p/9279097.html