Why jQuery has to receive 2 objects: body & html w

2019-07-05 05:13发布

问题:

In all the tutorials I found around the web on animating scrolling of the page with jQuery, I found that most of them are using the following code to do that:

$("html, body").animate(....

I was trying to find out why it's needed to animate 2 objects: html and body, but not luck. I might think it's needed to cover all major browsers… But why really, can someone explain please?

回答1:

chrome/safari uses html to animate, while firefox uses body (might be the other way around, don't remember!)

You could just use $(window).animate.