Anchor links with smooth scroll from page to page
-
Hi I am currently developing a site:
http://www.optimise-website-marketing.com/Problem is that the anchors will not use the smoth scrolling from one page to another. It work onlt when you are on the the same oage as the anchor.
Please help, im using the following script:
[ Code edited with backticks. Moderator note: when sharing code examples, please wrap the code in backticks or use the code button. ]
<script type="text/javascript">// <![CDATA[ $(document).ready(function() { function filterPath(string) { return string .replace(/^//,'') .replace(/(index|default).[a-zA-Z]{3,4}$/,'') .replace(//$/,''); } var locationPath = filterPath(location.pathname); var scrollElem = scrollableElement('html', 'body'); $('a[href*=#]').each(function() { var thisPath = filterPath(this.pathname) || locationPath; if ( locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) { var $target = $(this.hash), target = this.hash; if (target) { var targetOffset = $target.offset().top; $(this).click(function(event) { event.preventDefault(); $(scrollElem).animate({scrollTop: targetOffset}, 400, function() { location.hash = target; }); }); } } }); // ]]></script>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Anchor links with smooth scroll from page to page’ is closed to new replies.