LINK Anchor to Section Does Not Work in Firefox

Asked

Viewed 772 times

4

$(window).load(function() {
  $('a.scroll').each(function() {
    var id = $(this).attr('href');
    if (id.match('^#')) {

      var target = $(id).offset().top - 65;
      var title = $(this).attr('title');

      $(this).on('click tap', function() {
        $('body').animate({
          scrollTop: target
        }, 1000);
        history.pushState({
          foo: title
        }, title, id);
        return false;
      });
    }
  });
});

Same Page

<a href="pecas-servicos#qualidade" class="scroll" title="{!! trans('master.menu.qualidade')">Qualidade</a>

Other Page

<a href="pecas-servicos/contato#qualidade" class="scroll" title="{!! trans('master.menu.qualidade')">Qualidade</a>

When I am on the HOME page and I click on LINK it works to scroll to the section I clicked.

But if I am on another page the same does not happen. It even goes to HOME, however, descends to the bottom page.

  • these other pages are loaded inside the home ?

  • No. Other independent pages.

  • take a look and see if this can help you: http://stackoverflow.com/questions/3163615/how-to-scroll-html-page-to-given-anchor-using-jquery-or-javascript

  • It doesn’t work like that. It goes to the bottom of the page too. But if I give a enter in the address bar it goes to the right session... can not understand.

  • I don’t know if you’ve solved it yet and I know it has nothing to do with the problem, but why wait for the .load instead of $.ready?

  • Brother, what unnecessary stuff to be correcting Uppercase or Lowercase in the posts of 1930...

  • Are you talking about FRIENDLY URL? have moved your htaccess (there are 3 languages independent of the hosting server) to forward the site ... or already used <NAME>? and see http://www.w3schools.com/tags/att_a_name.asp

Show 2 more comments

1 answer

1


  • None worked.

  • I tested the code on two different versions of Firefox and it worked normally. But are you using any specific scroll library? Or what version of Firefox you need to work ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.