大家下午好,如何突出显示滚动中的活动菜单项并单击?
我想添加一个类active
到当前的滚动菜单项并点击。这是一个包含不同部分的单页(长)页面。当点击一个项目时,活动状态应该切换到当前状态。
我想出了下面的代码,但没有现在怎么我可以整合上面:
// Click event
$('#primary-navwrapper li a[href^="#"]').click(function(event) {
// Prevent from default action to intitiate
event.preventDefault();
// The id of the section we want to go to
var anchorId = $(this).attr('href');
// Our scroll target : the top position of the section that has the id referenced by our href
var target = $(anchorId).offset().top - offset;
console.log(target);
$('html, body').stop().animate({ scrollTop: target }, 500, function() {
window.location.hash = anchorId;
});
return false;
});
希望有人有一个例子或一些好的建议如何做到这一点。