Does scrollIntoView() work in all browsers? If not is there a jQuery alternative?

推荐答案

It is supported yes, but user experience is... bad.

As @9bits pointed out, this has long been supported by all major browsers. Not to worry about that. The main problem is the way that it works. It simply jumps to a particular element that may as well be at the end of the page. By jumping to it, users have no idea whether:

  • 页面已向上滚动
  • page has been scrolled down
  • they've been redirected elsewhere

前两个可以通过滚动位置来确定,但谁说用户在跳转之前一直跟踪滚动位置呢?所以这是一种不确定的行为.

The last one may be true especially if the page has moving header that gets scrolled out of view and remaining page design doesn't imply anything on being on the same page (if it also doesn't have any total height vertical element like left menu bar). You'd be surprised how many pages have this problem. just check them out yourself. Go to some page, look at it at top, then press End key and look at it again. It is likely that you'll think it's a different page.

Animated scrollintoview jQuery plugin to the rescue

这就是为什么仍然有plugins that perform scroll into view个,而不是使用原生DOM函数.它们通常会设置滚动动画,从而消除上述三个问题.用户可以轻松跟踪移动.

Jquery相关问答推荐

如何使用 jQuery 将表格的一行滚动到视图 (element.scrollintoView) 中?

JQuery 数据 Select 器不使用 .data 更新

jQuery 的 ajax 默认超时值是多少?

jQuery/JavaScript 碰撞检测

如何使用给定的 url 判断图像是否存在?

如何禁用在div内单击

使用跨域帖子发送凭据?

jQuery切换文本?

jQuery $.cookie 不是一个函数

jQuery中的Grep与过滤器?

将字符串true和false转为布尔值

获取跨域 iframe 的 DOM 内容

为什么不推荐$().ready(handler)?

在 jQuery UI 自动完成上没有检测到结果

判断文本框是否有空值

判断 JS 对象中是否存在键

如何在页面加载时启动 jQuery Fancybox?

jQuery vs jQuery Mobile vs jQuery UI?

如何使用 jQuery 取消设置元素的 CSS 属性?

使用javascript将HTML页面中的div下载为pdf