arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
275 stars 124 forks source link

scrollTop moody #52

Closed arvgta closed 9 years ago

arvgta commented 9 years ago
$('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