这是我的代码http://jsfiddle.net/sh8tmba6/1/
在ul&gt; li列表中有一个带有年份的导航栏。每个li都有<a>
个标记,其属性为data-menuanchor
。当用户根据data-menuanchor
点击这些链接时,相应的div必须滚动到顶部。
注意:即使向上或向下滚动,导航栏也必须固定
这是我尝试过的jquery代码,但它没有按照要求工作
('.timeline-nav li a').on('click', function (e) {
var yearID = '#' + $(this).data('menuanchor') ;
$('.historyWrapper').animate({
scrollTop: $(yearID).offset().top - $(yearID).parent().offset().top + $(yearID).parent().scrollTop()
}, {
duration: 1000,
specialEasing: {
width: 'linear',
height: 'easeOutBounce'
}
});
});
任何人都可以帮忙。提前致谢