Posted By

kate on 06/15/12


Tagged

navigation jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

BrockSamsom
atulkransingh


jquery snippet


 / Published in: jQuery
 

Simple nav snippet

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
  2. <script type="text/javascript">// <![CDATA[
  3. $(document).ready(function() {
  4. function filterPath(string) {
  5. return string
  6. .replace(/^\//,'')
  7. .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
  8. .replace(/\/$/,'');
  9. }
  10. $('a[href*=#]').each(function() {
  11. if ( filterPath(location.pathname) == filterPath(this.pathname)
  12. && location.hostname == this.hostname
  13. && this.hash.replace(/#/,'') ) {
  14. var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
  15. var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
  16. if ($target) {
  17. var targetOffset = $target.offset().top;
  18. $(this).click(function() {
  19. $('html, body').animate({scrollTop: targetOffset}, 2000);
  20. return false;
  21. });
  22. }
  23. }
  24. });
  25. });
  26. // ]]></script>

Report this snippet  

You need to login to post a comment.