3

I'm using Chris Coyier's plugin (actually, it is a modified version by Devin Sturgeon) to animate scrolling to anchor links:

// Easing for links pointing to anchors
$(document).ready(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});

It works perfectly until I apply overflow values with jQuery. For example, after I close a modal window, this piece of code is in charge of hiding horizontal overflow and setting vertical overflow to auto:

$('.file-content a.close-reveal-modal').on('click', function() {
  $('html, body').css({
    'overflow-y' : 'auto',
    'overflow-x' : 'hidden'
  });
});

After those values are applied, the plugin to animate scrolling to anchor links stops working, clicking on them doesn't produce any result whatsoever. If I remove the code in charge of setting the overflows when closing a modal, Chris' plugin works like a charm every single time.

Why is this happening?

Any sort of help will be very much appreciated!

1
  • Did you figure this out? Commented Dec 30, 2015 at 18:07

1 Answer 1

2

I don't know if this could help you, but here is a hint that I have found: http://upshots.org/javascript/jquery-get-real-height-of-hidden-or-overflow-hidden-elements

Did you try to debug it?

Because I suspect that in your example

target.offset().top
returns zero

Sign up to request clarification or add additional context in comments.

1 Comment

You might want to know, Beri, that Stackoverflow Netiquette discourages from using a URL-link derrogated posts. Rather include the merit here, in your post, once the referred page(s) need not be persistent forever so as to still provide your intended content. You might want to re-read the StackOverflow Do-s and Don't-s and re-edit your post to both show your will to comply with the Community Netiquette and also to avoid any adverse step from any Moderator who may feel necessary to enforce the said rules. Enjoy the great Community of contributing members you have decided to belong to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.