当您向下滚动页面时,让定位标记顺利滚动

当您向下滚动页面时,让定位标记顺利滚动

问题描述:

我正试图实现与phptherightway.com相同的结构。当你在右侧主页上滚动时,左侧会通过锚点跳下来,我认为它突出显示了左侧。我如何去重新创建?可以只使用锚标签来完成,还是需要更高级的东西,比如jquery?当您向下滚动页面时,让定位标记顺利滚动

右侧是否使用这个?

  • < A HREF = “#示例”>

虽然左侧使用?如果你希望页面

<div id="example">....</div> 

现在: - <名称= “榜样”>

+1

[点击锚点链接时JQuery的平滑滚动(可能重复http://*.com/questions/7717527/jquery-smooth-scrolling-when-clicking-an-anchor-link) – AleshaOleg

如果你点击这个锚链接:

<a href="#example">Click Me</a> 

该网页就会滚动#example部分而不是跳转,您将不得不使用jQuery scroll()

下面是scroll可以如何使用一个简单的jQuery例如:

$(function() { 
    $('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; 
     } 
    } 
    }); 
}); 

这里是与上述脚本的jsfiddle:http://jsfiddle.net/AndrewL32/65sf2f66/23/