ios禁止页面橡皮筋效果(附上原生和react的解决方案)
·
效果
在安卓上,页面是铺满且不可下拉的,但是在iPhone上整个页面可下拉,会露出空白
解决
原生:
$(document).ready(function(){
function stopScrolling( touchEvent ) {
touchEvent.preventDefault();
}
document.addEventListener( 'touchstart' , stopScrolling , false );
document.addEventListener( 'touchmove' , stopScrolling , false );
});
React Hooks:
useEffect(() => {
window.addEventListener('touchmove', {}, { passive: false });
return () => {
window.removeEventListener('touchmove', {});
};
}, []);
更多推荐

所有评论(0)