0

I have this problem with smooth scrolling on my website, where the script scrolls down to the <div>, but if you click the same <div> or any other <div>, it doesn't seem to understand where the next <div> is. Instead, it'll just bounce up and down around the same kind of area it was just at.

This is the website in question.

The script I'm using:

jQuery(document).ready(function() {

    jQuery('a[href^="#"]').click(function(e) {

        jQuery('#main').animate(
            {
                scrollTop: jQuery(this.hash).offset().top - 50
            }, 1000);

        return false;

        e.preventDefault();
    });
});

This will work fine only if I click the link when I'm at the top of the page, but won't work at all if it's from one link straight to the other.

Could someone have a look at the website and attempt to fix this please? As I'm a little out my depth with JavaScript.

Thank you.

Matheus Avellar
  • 1,507
  • 1
  • 22
  • 29
Mo Martin
  • 207
  • 3
  • 12
  • Seems to work just fine for me, can't replicate the issue? – Etheryte Feb 08 '15 at 20:02
  • Click one of the sidebar links twice in a row, it'll bounce from where it is back up to the top. And if i try going from one div to another it just doesn't really move – Mo Martin Feb 08 '15 at 20:23
  • Take a look http://stackoverflow.com/a/3432718/1181310 – Adrian Bolonio Feb 08 '15 at 20:43
  • Thanks, but i've just tried what was suggested and all it seemed to do was stop it from working all together, i'm sure it's a matter of misslinking stuff up, but i'm no good with javascript to really know what it might be. – Mo Martin Feb 08 '15 at 22:09
  • On a sidenote, `return false;` returns (closes) the function, so the `e.preventDefault()` is never going to run. I'd suggest moving it to a line above the `return` statement. – Matheus Avellar Mar 02 '17 at 04:16

0 Answers0