I am following this post.
Scroll to the center of viewport
I do like the answer but when I use it, I got an error in my console.
$('body').animate({
scrollTop: $(this).offset().top - ($(window).height()-$(this).outerHeight(true)) / 2
}, 5000);
The error:
Uncaught TypeError: Cannot read property 'top' of undefined
I am not sure why $(this).offset() is undefined
. Can anyone help me about it?
Thanks!