So I am on a hunt to try and figure out the best ways of optimizing the Jquery .animate(scrollTo:value) function. Take this example:
$('#returnToTop').on('click', function(){
$('html, body').animate({
scrollTop: 0
}, 'slow');
});
Here you have a div which acts as a "Top" button that when clicked, scrolls the page back to the top. Now on complicated pages, this is rather jerky and not smooth. I was wondering if any jQuery ninjas could enlighten us as to what exactly the animate function does. On simple pages, it's nice and smooth.
Now, I assume that it probably does some calculations that walks down the DOM, so when it's complicated, it takes a while and looks jumpy. So here's the heart of the matter:
are there any steps we can take, as developers to provide jQuery with the precise parameters that would make it's calculations simpler, therefore making the animation smoother. There are probably specific values that are important that if provided, would provide a significant speedup.
Does anyone have any insight?
Thanks.