0

The solution: Scroll if element is not visible

shows how to scroll to see a component using jQuery. Is there a portable way to do that directly, or is it different per browser and therefore jQuery is the only way?

Community
  • 1
  • 1
Dov
  • 8,000
  • 8
  • 46
  • 75
  • 1
    Do you need to create a smooth scroll animation or is it fine if just jumps to the component? – Jackson Jun 16 '15 at 15:19

1 Answers1

1

Most of the old functions which weren't been deprecated are supported by a very large panel of browsers (at least the browsers used by 99.99% of the internet users). You can check the method scrollTo() and provide x and y coordonates as argument.

Ex : window.scrollTo(500, 100);

Here the compatiblity is OK with Firefox, IE, Safari, Chrome and Opera.

Source : http://www.w3schools.com/jsref/met_win_scrollto.asp

Of course, I advise the use of jQuery for these kinds of actions but it can be made without it with not any problem. As @Jackson noticed, speaking about animation, you'll have hard time to animate your scrolling with raw javascript though.

Alex
  • 4,599
  • 4
  • 22
  • 42