最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How come $('html').animate() only works in IE and $('body').animate() is needed for

programmeradmin1浏览0评论

I have to use $('html, body').animate() to make the snippet fully cross-browser patible, but this is inconvenient when chaining animations as they will sometimes act on both <html> and <body>.

IE8 depends on having 'html' while Chrome or Safari depend on having 'body', so therefore i must include both.

Why the discrepancy?

I have to use $('html, body').animate() to make the snippet fully cross-browser patible, but this is inconvenient when chaining animations as they will sometimes act on both <html> and <body>.

IE8 depends on having 'html' while Chrome or Safari depend on having 'body', so therefore i must include both.

Why the discrepancy?

Share Improve this question edited Mar 8, 2011 at 22:55 trusktr asked Mar 8, 2011 at 10:53 trusktrtrusktr 45.5k58 gold badges210 silver badges287 bronze badges 5
  • Which version(s) of IE does this pertain to? – BoltClock Commented Mar 8, 2011 at 10:54
  • @BoltClock - I'd imagine all as I doubt MS would change the fundamental way the browser is built – Alex Commented Mar 8, 2011 at 10:58
  • @Alex: They did do something with the DOM near the root level though. In IE6, html wasn't the root element; in IE7, html and one other element were at the root level. – BoltClock Commented Mar 8, 2011 at 11:02
  • to pensate for many things that do not work in IE,but work in all other browsers. – DhruvPathak Commented Mar 8, 2011 at 11:02
  • see updated question. basically html is for IE and body is for Chrome/Safari. – trusktr Commented Mar 8, 2011 at 22:56
Add a ment  | 

2 Answers 2

Reset to default 5

I think it's because the scroll bars (that I presume you're animating) are built into the browser at different locations. I've had this problem before and had to use the same method you incorporate. Bit annoying, but then so are most things when you want them to work across all browsers :-)

You should never even do $('html').animate since you should only animate content and the html tag is not a content tag. Stick with $('body').animate and it should work in all browsers.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论