Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element option not working when target id isn't a direct child of element #19

Open
HugoPoi opened this issue Jul 11, 2017 · 0 comments
Open

Comments

@HugoPoi
Copy link

HugoPoi commented Jul 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant