$('html,body')。animate和$('body')。animate之间的区别? [英] difference between $('html, body').animate and $('body').animate?
本文介绍了$('html,body')。animate和$('body')。animate之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,要滚动到页面上的某个元素(例如:如何转到页面上的特定元素?)
For example, to scroll to a certain element on the page (ie here: How to go to a specific element on page?)
$("#fromTHIS").click(function() {
$("html, body").animate({ scrollTop: $("#toTHIS").offset().top }, 500);
return true;
});
我已经尝试了两种方式,他们都认为他们正在做这项工作。我缺少什么?
I've tried both and they both look that they are doing the job. What am I missing?
推荐答案
你使用选择器的原因 $('html,body ')
是因为网络浏览器不一致。经过几次测试后,我发现了三件事:
The reason you use a selector for BOTH $('html, body')
is because of web browser inconsistency. After a few tests I have found three things:
- 浏览器
Firefox
&IE
利用此选择器的html部分 - webkit类中的浏览器例如:
Safari
和Chrome
向身体回复
。 -
虽然可以避免所有问题一起使用$(文件)
代替。
- The browsers
Firefox
&IE
utilize the html portion of this selector - Browsers in the "webkit class" eg:
Safari
andChrome
respond to the body. Although one can avoid the issue all together by using$(document)
instead.
jQuery bug跟踪器上还有一张票在此明确说明此问题
There's also a ticket on the jQuery bug tracker specifically stating this issue here
这篇关于$('html,body')。animate和$('body')。animate之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文