javascriptjquerydom

JavaScript scrollTo method does nothing?


So I am desperatley trying to get some scrolling functionality to work on a page. After not having a luck I decide to just stick window.scrollTo(0, 800); on my page to see if I could get any scrolling to happen. Nothing does happen. I have an accordion that expands and then I want to scroll to a specific element with in it. But for now I would be happy to just see the thing scroll at all. Anyone run into this?

Thanks!


Solution

  • I was able to resolve this problem using jQuery method animate(). Here is an example of the implementation I went with:

    $('#content').animate({ scrollTop: elementOffset }, 200);
    

    The selector is getting the div with ID = "content". I am then applying the animate method on it with scrollTop as an option. The second parameter is the time in milliseconds for the animation duration. I hope this helps someone else.