my function causes a sluggish behaviour of scrolling
$(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';
}
}
});
});
});
I read about a debounce function (https://davidwalsh.name/javascript-debounce-function), but unfortunately I can not make it work with my function.
Can somebody please give me a hint how to implement the debounce to the function? thank you in advance!