scrollTop moody #52

Closed
arvgta opened this Issue Mar 30, 2015 · 0 comments

Projects

None yet

1 participant

@arvgta
Owner
arvgta commented Mar 30, 2015
$('html, body').animate({ 
        scrollTop: $('#' + url.split('#')[1]).offset().top
    }, 500);
}

The above code works, when a link with a '#' is pressed after the new page has been loaded beforehand e.g. in "Recent Comments" (in the sidebar) on http://4nf.org/.

It doesn't work though when clicking e.g. "Google Analytics handling documented" on the homepage of http://4nf.org/ (with the following URL: http://4nf.org/installation/#gasetup). (If I dump the URL into the browsers address bar, it works)

A scroll is performed, but to the very bottom of the page...

Any ideas why?

I have provided the id like this:

<h1 id="gasetup"><span style="color: #008000;">Google Analytics Setup</span></h1>

EDIT: Now using the following up-to-date Pronto code:

var $el = $('#' + url.split('#')[1]), scrollTop;

if ($el.length) {
    scrollTop = $el.offset().top;
}

if (scrollTop !== false) {
     $window.scrollTop(scrollTop);
}

The same result as above

So, I reckon that parts of the "ajaxification" interfere with calculating the offset...
But what could that be??

EDIT. Solved(presumably)

The second animate() was running in the background, while the scroll was being performed.
Solved by introducing the function _doRender2() as a callback in the animate() call...

Test file

@arvgta arvgta closed this Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment