2013-04-22 70 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; 
     } 
    } 
}); 
相關問題