When using element option and the target id isn't a direct child of element.
<div class="container-with-scroll">
<h2 id="working-target"></h2>
<a><img id="target"></a>
</div>
// This working great :
$('#working-target').animatescroll({ element: '.container-with-scroll', padding: 20 });
// This not working :
$('#target').animatescroll({ element: '.container-with-scroll', padding: 20 });
Problem is here https://github.com/ramswaroop/animatescroll.js/blob/master/animatescroll.js#L162
The use of this.parent() causing the issue because the parent of target is <a> not the .container-with-scroll.
The fix:
$(opts.element).stop().animate({ scrollTop: this.offset().top - $(opts.element).offset().top + $(opts.element).scrollTop() - opts.padding}, opts.scrollSpeed, opts.easing);
I can do a PR if needed.
When using element option and the target id isn't a direct child of element.
Problem is here https://github.com/ramswaroop/animatescroll.js/blob/master/animatescroll.js#L162
The use of
this.parent()causing the issue because the parent of target is<a>not the.container-with-scroll.The fix:
I can do a PR if needed.