Jquery滚动到第页的锚定标记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jquery滚动到第页的锚定标记相关的知识,希望对你有一定的参考价值。

You will want to include the jquery easing plugin: http://gsgd.co.uk/sandbox/jquery/easing/

Add a class of 'scroll' to any element that should slide to an anchor tag. You must give the anchor tag an id equal to the name.
  1. $(document).ready(function(){
  2. $(".scroll").click(function(event){
  3. //prevent the default action for the click event
  4. event.preventDefault();
  5.  
  6. //get the full url - like mysitecom/index.htm#home
  7. var full_url = this.href;
  8.  
  9. //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
  10. var parts = full_url.split("#");
  11. var trgt = parts[1];
  12.  
  13. //get the top offset of the target anchor
  14. var target_offset = $("#"+trgt).offset();
  15. var target_top = target_offset.top;
  16.  
  17. //goto that anchor by setting the body scroll top to anchor top
  18. $('html, body').animate({scrollTop:target_top}, 2000, 'easeOutQuad');
  19. });
  20. });

以上是关于Jquery滚动到第页的锚定标记的主要内容,如果未能解决你的问题,请参考以下文章

jQuery找到具有精确href的锚标记

如何使用 jquery 识别具有 data-href 属性的锚标记

javascript jQuery - 平滑锚定滚动

javascript jQUery - 平滑锚定滚动

javascript jQuery - 平滑锚定滚动

基于jquery的锚点滚动插件(百度百科效果) anchorScroll.js