简体   繁体   English

使命名锚链接滚动到div

[英]Making named anchor links scroll to div

Here's my site I'm having issues with: http://www.londonadvertising.com/2011/ 这是我的网站,存在以下问题: http : //www.londonadvertising.com/2011/

It's a one page site and all the hyperlinks go to an area of the page using an anchor. 这是一个页面站点,所有超链接都使用锚点转到页面的某个区域。 Click a link such as: 单击一个链接,例如:

<a href="#news">News</a>

and it will jump down to the section: 它将跳到以下部分:

<li id="news" class="section_wrapper">

What is the best way using jQuery to make the jump to section a smooth scroll to section? 使用jQuery使跳转到段落平滑滚动到段落的最佳方法是什么?

Many Thanks Tim 非常感谢蒂姆

Just a classic idea: 只是一个经典的主意:

DEMO jsBin 演示jsBin

$('#nav li').click(function(){
  var liInd = $(this).index();
  var pagePos = $('.page').eq(liInd).position().top;

  $('body').stop(1).animate({scrollTop: pagePos},1000); 
}); 

您可以使用jquery插件jQuery.ScrollTo,它具有平滑的scrool和多种效果,例如使用它的示例:

$.scrollTo( '#target-examples', 800, {easing:'elasout'} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM