kisukedeath

Desplazamiento con anclas

Oct 3rd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Desplazamiento con anclas */
  2. $(function(){
  3.  
  4.         $('a[href*=#]:not([href=#])').click(function() {
  5.            if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
  6.                var target = $(this.hash);
  7.                target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  8.                   if (target.length) {
  9.                     $('html,body').animate({
  10.                         scrollTop: target.offset().top
  11.                    }, 1000);
  12.                    return false;
  13.                }
  14.            }
  15.        });
  16. });
  17.  
  18. HTML
  19. -----------------------------------------
  20. <ul>
  21.                         <li><a href="#read">Read</a></li>
  22.                         <li><a href="#widget">Widget</a></li>
  23.                         <li><a href="#info">Infographic</a></li>
  24.                     </ul>
  25. <div id="read">
  26. </div>
  27.  
  28. <div id="widget">
  29. </div>
  30.  
  31. <div id="info">
  32. </div>
Advertisement
Add Comment
Please, Sign In to add comment