0

There is a contact form at the bottom of my home page. I have a "contact" link in my navigation bar that scrolls the user down to the contact section on the home page. It works sometimes but sometimes does not scroll the user the whole way. The distance and frequency it comes up short seems to be random.

Here is the code:

$(document).ready(function() {

/*
   If they reached the home page from the contact link
   contact is the id of the section I want to scroll to
   I get the offset of that section from the top
   Then use jquerys .animate to scroll
*/
if($(location).attr('pathname') == "/contact") {
    var contactOffset = $('#contact').offset().top;
    var contactHeight = contactOffset

    $('html body').animate({
        scrollTop : contactHeight
    }, 1000)
}

I followed the example from the jQuery website. What am doing that is causing the inconsistency?

Thanks in advance.

Four_lo
  • 1,150
  • 10
  • 28
  • I tried `162.144.149.48/contact` several times and it worked fine consistently. – Barmar May 12 '15 at 02:19
  • Doesn't work in firefox ^ @Barmar – imbondbaby May 12 '15 at 02:19
  • Confirmed. The Scroll button also doesn't work. – Barmar May 12 '15 at 02:24
  • 1
    worked fine for me! I wanted to point out one more thing, i think there is something wrong the way it is implemented! The page refreshes everytime you click "contact"! Why dont u use an "Id" and then redirect the link to the id. it is much simpler and page does not refresh! – wallop May 12 '15 at 03:05

0 Answers0