Does scrollIntoView()
work in all browsers? If not is there a jQuery
alternative?
Does scrollIntoView()
work in all browsers? If not is there a jQuery
alternative?
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 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 plugin to the rescue这就是为什么仍然有plugins that perform scroll into view个,而不是使用原生DOM函数.它们通常会设置滚动动画,从而消除上述三个问题.用户可以轻松跟踪移动.