本文介绍了$('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:


  1. 浏览器 Firefox & IE 利用此选择器的html部分

  2. webkit类中的浏览器例如: Safari Chrome 向身体回复


  1. The browsers Firefox & IE utilize the html portion of this selector
  2. Browsers in the "webkit class" eg: Safari and Chrome respond to the body.

jQuery bug跟踪器上还有一张票

There's also a ticket on the jQuery bug tracker specifically stating this issue here

这篇关于$('html,body')。animate和$('body')。animate之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:00