禁止微信h5自带的下拉事件
//禁止微信h5自带的下拉事件 var app = document.querySelector(".messageChat"); console.log(app, 990); var touchstartY; app.addEventListener( "touchstart", function (event) { console.log(1); var events = event.touches[0] || event; touchstartY = events.clientY; //获取触摸目标在视口中的y坐标 }, false ); app.addEventListener( "touchmove", function (event) { var events = event.touches[0] || event; //注意app.scrollTop始终为0 var scrollTop = app.scrollTop || document.documentElement.scrollTop; //获取滚动部分的高度 var clientHeight = document.documentElement.clientHeight; //获取手机屏幕高度(可视部分高度) var scrollHeight = app.scrollHeight; //所有内容的高度 if ( events.clientY > touchstartY && scrollTop === 0 && event.cancelable ) { event.preventDefault(); //禁止到顶下拉 } else if ( scrollTop + clientHeight > scrollHeight && event.cancelable ) { // event.preventDefault(); //禁止到底上拉 } }, false );