I need to do scroll to the item loaded by ajax, but after loading the contents, nothing happens, the page is always at the top. When I click refresh button (the page is reloaded dynamically with content caching), the page scrolls to the designated target.
var startPageLoader = function( pid, sid, url ) {
loader( 'show' );
$.ajax( {
url : cCore.Settings[ 'url' ] + '/page/',
method : 'POST',
data : { _t : 'page', _pid : pid, _sid : sid },
dataType : 'json',
success : function( ret ) {
if( !ret[ 'status' ] ) {
loader( 'hide' );
return;
}
loader( 'hide' );
$( '#mainWrapper > .content article.subpage' ).hide( ).html( ret[ 'data' ] ).fadeIn( );
if( url != null ) {
if( sid.length )
url += '#' + sid;
history.pushState( {}, '', url );
}
aProduct[ 0 ] = pid;
cCore.Plugins[ "modalTooltip" ].rebuild( );
prepareGallery( );
scrollToSection( sid );
}
} );
};
var scrollToSection = function( sid ) {
if( !sid.length )
return;
aProduct[ 1 ] = sid; // sid is an name of target
var offset = $( "#" + sid ).offset( ).top;
$( 'html, body' ).animate( {
scrollTop: offset
}, 1000 );
};
I think that could be issue with the document height, but i'm not sure.
Thanks.