my problem is as following: On my website I want my anchor links to smoothly scroll to the ids they are linked to. There are many threads with solutions to this problem, however I am only able to use these on a jsfiddle sample project https://jsfiddle.net/7fcvkwf0/16/
$("a").each(function(index, element){
$(this).click(function(e) {
if (this.hash != "" && $(this).attr("href").charAt(0)=="#"){
e.preventDefault();
var id = $(this).attr("href");
$('html, body').animate(
{scrollTop: $(id).offset().top},
1000,
"swing",
function(){
console.log("done");
});
window.location.hash = id;
}
});
});
is the function I use to make the animation smooth. I don't know why, but I use the exact same code on my own homepage but it doesn't seem to work because it jumps to the anchor links immediately. The console log appears after 1000ms (1s). Unfortunately I can't show you the problem because I can't reproduce it in jsfiddle (I don't know why).