使用JS实现页面内跳转的两种方式

第一种方式是直接使用锚点配合链接标签:

<h2 id="h2-anchor">Scroll to here</h2><a href="#h2-anchor">Jump to H2</a>现在大多数实现都采用该种方式。但是这种方式没有动画效果,跳转是直接发生的。

第二种方式使用jQuery中的animate方法实现:

var target= $('#h2-anchor').offset().top;$('body').animate({scrollTop:target}, 300);这种方式跳转的过程更自然。

,灯红酒绿的城市,登上楼顶,俯视万家灯火,

使用JS实现页面内跳转的两种方式

相关文章:

你感兴趣的文章:

标签云: