JQuery简单实现锚点链接的平滑滚动

 

 

<a id="turnToContent" href="#content"></a>

 

h2>
<a id="content">HTML5</a>
</h2>
<p>
html5html5html5
</p>
<p class="addMes">标签: <span>HTML5</span><small>2015年4月19日</small></p>
</div>

 

 

<script type="text/javascript">  
            $(document).ready(function(){  
$('#turnToContent').click(function () {
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 500);
return false;
});
  });  
        </script> 

 

posted @ 2016-12-14 19:11  王传明  阅读(101)  评论(0)    收藏  举报