我也有这个问题。而我通过让点击导航锚点的时候让javascript来滚动nav来解决它。并且由于在手指放开屏幕之前正常的触摸滚动不会产生事件,所以我使用position:fixed,这使得触摸滚动比JavaScript更好,请参阅apples dev-site。
这不是最终的解决方案,但在我看来,它总比没有工作好。这个脚本还检查窗口的宽度,以确保它只适用于较小的屏幕,以及设备。
这里是我的代码,如果你觉得有用,使之更好地或找到一个更好的解决方案,请分享:)
/* NAV POSITION */
var specScroll = false; // If special scrolling is needed
/* Check what kind of position to use.*/
(function navPos() {
var width = checkWidth();
if (width <= 480 || navigator.userAgent.match(/iPad/i) != null) {
specScroll = true;
}else{
specScroll = false;
window.onscroll = NaN;
}
})();
$(window).resize(function(){ navPos(); }); // After resizing, check what to use again.
/* When clicking one of the nav anchors */
$(function() {
$('a').bind('click',function(e){
var $anchor = $(this);
if(specScroll){
$('#nav').css('position', "absolute");
window.onscroll = anchorScroll;
}
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 700,'easeOutExpo', function(){
if(specScroll){setTimeout("window.onscroll = touchScroll;", 100);}
// the set timeout is needed for not overriding the clickability of the anchors after anchor-scrolling.
});
e.preventDefault();
});
});
/* While the user clicks and anchors in nav */
function anchorScroll() { $('#nav').css('top', window.pageYOffset); }
/* the first time the user scrolls by touch and lift the finger from screen */
function touchScroll() {
$('#nav').css('position', 'fixed');
$('#nav').css('top', 0);
window.onscroll = NaN;
}
/* CHECK WIDTH OF WINDOW */
function checkWidth() {
myWidth = 0;
if(typeof(window.innerWidth) == 'number') {
myWidth = window.innerWidth; //Non-IE
} else if(document.documentElement && (document.documentElement.clientWidth)) {
myWidth = document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
} else if(document.body && (document.body.clientWidth)) {
myWidth = document.body.clientWidth; //IE 4 compatible
}
return myWidth;
}
我使用项目页面上该解决方案,尝试一下:敢.niklasek.se