At the bottom of my homepage, I included a contact form and indicated the anchor for this section as div id = "contact".
When the contact button on any page is pressed, it should go to the home page and load the page, automatically scroll to the contact form.
I was unsuccessful after looking through a similar question that I found here: jQuery scrolls to ID from another page. When I try, it just jumps to the form. I want it to scroll smoothly.
<li><span>Get in touch</span><a href="index.html#contact">Contact</a></li>
Function jquery problems to navigate to the contact anchor on the home page from other pages:
(function($){ var jump=function(e) { if (e) { e.preventDefault(); var target = $(this).attr("href"); } else { var target = location.hash; } $('html,body').animate({ scrollTop: $(target).offset().top },1000,function() { location.hash = target; }); } $('html, body').hide() $(document).ready(function() { $('a[href^=#]').bind("click", jump); if (location.hash) { setTimeout(function(){ $('html, body').scrollTop(0).show() jump() }, 0); } else { $('html, body').show() } });
I'm trying to achieve something similar to this example: http://vostrel.cz/so/9652944/page.html the difference is that instead of the "binding identifier" in this which is displayed on both pages, the binding identifier (contact) for me displayed on only one page (at home).
source share