I want to navigate to a div inside an iframe using jQuery.animate
from a link outside the iframe.
This is the Code I use:
function scrollToAnchorIframe(aid){
var aTag = window.frames['myFrame'].document.getElementById(aid);
$('html,body').animate({scrollTop: aTag.offset().top - 62},'slow');
}
However, it doesn't work, logging the error "Object [object HTMLElement] has no method 'offset'
". Is there a way to get the offset of the id to make it work?
Update (Solved): That's the code I'm using now:
function scrollToAnchorIframe(aid){
var aTag = window.frames['myFrame'].document.getElementById(aid);
jQuery('html,body').animate({scrollTop: $(aTag).offset().top + $("#myFrame").offset().top - 62},'slow');
}
aTag
is DOM element , make it jQuery object
$('html,body').animate({scrollTop: $(aTag).offset().top - 62},'slow');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With