Found on the Internet can prevent the page scroll to the top or bottom of the time, the leakage of the small letter ugly Gray bottom, the following little part of the core code to share for everyone's reference!
My core code:
Prevent:function () {var startx = 0, starty = 0;//touchstart event function Touchsatrtfunc (evt) {try {//evt.preventdefaul T (); To prevent the browser zoom, scroll bar scrolling, etc. var touch = evt.touches[0]; Gets the first contact var x = number (Touch.pagex); Page contact x coordinate var y = number (touch.pagey);
Page Contact y-coordinate//record contact initial position startx = x;
Starty = y;
catch (E) {alert (' Touchsatrtfunc: ' + e.message);}}
Document.addeventlistener (' Touchstart ', Touchsatrtfunc, false);
var _ss = document.getElementById ("contain"); _ss.ontouchmove = function (ev) {var _point = ev.touches[0], _top = _ss.scrolltop;//When to bottom var _bottomfaval = _ss.scro
Llheight-_ss.offsetheight; Reach Top if (_top = = 0) {//block slide down if (_point.clienty > Starty) {ev.preventdefault ();} else {//block bubbling//normal execution Ev.sto
Ppropagation (); } else if (_top = = _bottomfaval) {//Reach bottom//block up sliding if (_point.clienty < Starty) {Ev.preventdefault ();} else {//
Block bubbling//Normal execution ev.stoppropagation (); } else if (_top > 0 && _top < _bottomfaval) {ev.stoppropagation ();}else {ev.preventdefault ();}}; }
The above code is small series to introduce the micro-letter page scrolling threadbare core code, the code is relatively simple, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone!