0
使用iScoll.js即時幫助在iOS上滾動動畫。基本上它使用硬件加速的CSS屬性來移動內容,而不是傳統的滾動。使用iScroll.js的iOS動畫錨點滾動方法
iScoll運行良好,但我也試圖實現平滑的滾動錨點解決方案。
它可以在桌面上正常工作,但問題是我無法制定如何檢索正確的偏移值以傳遞給iScoll實例。我覺得像IM超接近的解決方案:
var ua = navigator.userAgent,
isMobileWebkit = /WebKit/.test(ua) && /Mobile/.test(ua);
if (isMobileWebkit) {
iScrollInstance = new iScroll('wrapper');
}
$('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) {
if (isMobileWebkit) {
iScrollInstance.refresh();
/* issue here with "target.position.top" = "undefined" */
iScrollInstance.scrollTo(0, target.position.top, 1000);
}else{
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
}
return false;
}
}
});
充分演示這裏http://jsfiddle.net/Wccev/3/