2013-04-22 71 views
-1

I have this code:我如何可以移动到<a name tag slowly?

<a name="point1"> < /a> // at the very beginning 

<a href="link.php#point1"> Link1 < /a>  // at the very end 

when you click on Link1 the browser moves fast to the point1
Can I make the browser to move slowly?

回答

1

This is quite easy to do with jQuery by animating the scrollTop of the html and body:
http://css-tricks.com/snippets/jquery/smooth-scrolling/

下面是a comment该网页上的一个片段:

$('a[href*=#]:not([href=#])').click(function() { 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
     || location.hostname == this.hostname) { 

     var target = $(this.hash); 
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
      if (target.length) { 
      $('html,body').animate({ 
       scrollTop: target.offset().top 
      }, 1000); 
      return false; 
     } 
    } 
});