效果

在安卓上,页面是铺满且不可下拉的,但是在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', {});
    };
  }, []);

更多推荐