你可以使用这个:
CSS
.navigation { position:fixed; top:0; left:0; width:100%; background-color:#88f; }
.navigation a { margin:2em; color:white; text-decoration:none; }
.navigation a.active {text-decoration:underline; color:red;}
#resume { margin-top:50px; }
section { margin:2em; height:500px; background-color:#eee; }
jQuery
$(function(){
var links = $('.navigation>a'); //.not('.contact');
var sections = $('section');
links.click(function(e){
e.preventDefault();
var p = $(this.getAttribute('href')).position().top;
$("html, body").stop().animate( { scrollTop: (p-30)+'px' }, 500);
});
$(window).on('scroll', function(e){
var i=0;
sections.each(function(j){
var br = this.getBoundingClientRect();
if (br.top<150) { // distance from the top of screen
i = j;
}
});
var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
if (scrollBottom < 40) { // highlight the last section
i = sections.length-1;
}
links.removeClass('active');
var active = sections.eq(i).attr('id');
links.filter('[href="#'+active+'"]').addClass('active');
}).trigger('scroll');
});
JSFiddle: http: //jsfiddle.net/GRcjc/3/ http://jsfiddle.net/GRcjc/3/show