I found numerous questions and answers here on stackoverflow about JQuery smooth scroll, but I still fail to understand how it works.
var $root = $('html, body');
$('a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
return false;
});
- Why do we select html and body not just body?
animate()
, animates the content of the$root
variable, right?- Why is an object passed to
animate()
function? - What is scrollTop, a css property?