我这边是查阅材料,写了个JS版的函数:
IOS_STOP_preventDefault() { let startY, endY; const scrollTop = document.documentElement.scrollTop || document.body.scrollTop; const clientHeight = document.documentElement.clientHeight || document.body.clientHeight; const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; document.addEventListener( 'touchstart', function (e) { startY = e.touches[0].pageY; }, { passive: false } ); document.addEventListener( 'touchmove', function (e) { endY = e.touches[0].pageY; //记录手指触摸的挪动中的坐标 //手指下滑,页面达到顶端不能持续下滑 if (endY > startY && scrollTop <= 0) { e.preventDefault(); } //手指上滑,页面达到底部不能持续上滑 if (endY < startY && scrollTop + clientHeight >= scrollHeight) { e.preventDefault(); } }, { passive: false } ); }
当咱们判断以后环境是IOS环境时,在onload/onready/或各种框架生命周期里调用即可
原链接https://www.cnblogs.com/cuncu...