Does scrollIntoView()
适用于所有浏览器?如果没有的话有没有jQuery
选择?
是的,但用户体验很差。
正如@9bits 指出的那样,这长期以来一直是所有主流浏览器都支持 https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView#Browser_compatibility。不用担心这个。主要问题是它的工作方式。它只是跳转到可能位于页面末尾的特定元素。通过跳转到它,用户不知道是否:
- 页面已向上滚动
- 页面已向下滚动
- 他们已被重定向到其他地方
前两个可以通过滚动位置来确定,但谁说用户在跳转完成之前就记录了滚动位置?所以这是一个不确定的动作。
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.
动画scrollintoview
jQuery 插件来救援
这就是为什么仍然有执行滚动到视图的插件 http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html而不是使用原生 DOM 函数。它们通常会设置滚动动画,从而消除上述所有 3 个问题。用户可以轻松跟踪运动。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)