MothraDactyl MothraDactyl - 4 months ago 31
Javascript Question

Window scrollY = 0 on Highcharts redraw()

I'm using Highcharts 3.0.2

I have a div#chart and two js variables,

var options1 = {...}, options2 = {...}
. These contain distinct highcharts options (chart 1 and 2, let's say).

On document-ready, js calls
. This happily generates chart 1.

I have a click event listener that calls

When clicked, chart 2 is happily generated (replacing chart 1 in div#chart).

HOWEVER! When chart 2 is generated, something resets the window.scrollY to zero. In other words, if the user has scrolled down from the top of the page when clicking, then the window moves back to the top.

What is causing this behavior, and how can I stop it?

If I wanted it to look as if the page refreshed, I would have it refresh! AHHH!!!

The Fiddle: jsFiddle


You can save the scroll position like this:

var tempScrollTop = $(window).scrollTop();

Then after changing your chart and page title, set it back:


Here's the DEMO