我的功能导致滚动缓慢
$(function() {
var currentHash = "top";
$(document).bind('scroll', function(e) {
$('.content section, .scrollpos').each(function() {
var hash = $(this).attr('data-anchor');
if (
$(this).offset().top < window.pageYOffset + 330 && $(this).offset().top + $(this).height() > window.pageYOffset + 330 && currentHash != hash
) {
if (history.pushState) {
history.pushState(null, null, "#" + hash);
} else {
window.location.hash = '#myhash';
}
}
});
});
});
我读到了一个去抖函数(https://davidwalsh.name/javascript-debounce-function),但不幸的是我不能让它与我的函数一起工作。
有人可以给我一个提示如何实现函数的去抖动吗?先感谢您!