scrollIntoView适用于所有浏览器吗? [英] Does scrollIntoView work in all browsers?

查看:1417
本文介绍了scrollIntoView适用于所有浏览器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scrollIntoView()可以在所有浏览器中使用吗?如果没有 jQuery 替代?

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

推荐答案

支持是,但是用户体验很糟糕。



正如@ 9bits指出的那样,这一直是。不用担心。主要问题是它的工作方式。它只是跳转到一个特定的元素,也可能在页面的末尾。通过跳转到它,用户不知道是否:

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:


  • 页面已向上滚动

  • 页面向下滚动

  • 他们已被重定向到其他地方

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

The first two can be determined by scroll position, but who says users kept track of scroll position before jump was done? So it's an nondeterministic action.

最后一个可能是真的,特别是如果页面有移动标题,滚动出视图和剩余页面设计并不意味着在同一页面上有任何东西(如果它也没有任何总高度垂直元素,如左菜单栏)。有多少页面有这个问题你会感到惊讶。亲自检查一下。转到某个页面,在顶部查看,然后按结束键并再次查看。您可能认为这是一个不同的页面。

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.

这就是为什么还有插件执行滚动到视图而不是使用本机DOM功能。它们通常动画滚动,消除了上面列出的所有3个问题。用户可以轻松跟踪移动。

That's why there still are plugins that perform scroll into view instead of using native DOM function. They usually animate scrolling which eliminates all 3 issues outlined above. Users can easily keep track of the movement.

这篇关于scrollIntoView适用于所有浏览器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆