hey guys,
i’m loading a div from a subsite with ajax. this subsite has a link in it like this:
<a href="#someIDonHomepage">anchorlink</a>
My homepage where the ajax request is fired has this #someIDonHomepage div and i want my page to jump to that position.
However since i’m loading the anchor with ajax this doesn’t work.
any idea how i could solve that?
I wrote this animated scroll script with jquery that animates the jump when clicking on anchors.
/*Animated scroll for anchorlinks*/
var anchor = '',
pageOffset = '',
viewOffset = 30,
scrollPos = '';
$(function() {
$("a[href*='#']").each(function() {
$(this).addClass('anchorLink');
$(this).bind('click', function(e) {
e.preventDefault();
anchor = $(this).attr('href').split('#')[1];
pageOffset = $("a[name='#"+anchor+"']").offset();
scrollPos = pageOffset.top - viewOffset;
$('html, body').animate({scrollTop:scrollPos}, '500');
})
});
});
Any idea how i could solve that? thank you
jQuery Ajaxy has built in support for using ajax with hashes, as well as backwards support for traditional anchors – click the durian tab in the demo.
http://balupton.com/sandbox/jquery-ajaxy/demo/