首页 > 如何禁用 iOS elastic scrolling 的 bounce effect?

如何禁用 iOS elastic scrolling 的 bounce effect?


如图所示。


拖動是 drag,這個是滾動,scroll。iOS 首創的「彈性」滾動(elastic scrolling)。

解決方案一:屏蔽 touchmove 事件。缺點:徹底無法滾動,內容溢出時體驗不好
解決方案二:將可能溢出部分放入 overflow: auto 的 div 中,並 -webkit-overflow-scrolling: touch,這樣既可以查看溢出部分,又不會導致整體被滾動。

然而當子元素無法繼續滾動時,繼續滾動依舊會導致整體被彈性滾動。解決方案:

html, body { height: 100%; }
body { overflow: hidden }
body > div, body > div > div { height: 100%; overflow-y: auto; overflow-x: visible; -webkit-overflow-scrolling: touch }

然後,將可能溢出的內容放到 body > div > div 中。

// PS: iOS 8 貌似不行了,只能 document.ontouchmove = function(e) { e.preventDefault(); }


需要jq或者zepto组件,组件里有具体方案,方法为:
$(window).on('scroll.elasticity',function (e){e.preventDefault();}).on('touchmove.elasticity',function(e){e.preventDefault();});
具体原理应该跟楼上说的差不多,但是会更多方案组合。

【热门文章】
【热门文章】