This article mainly introduces how to implement the touch screen drag function on the mobile terminal based on javascript. If you are interested, refer to this article to share the touch screen drag function on the mobile terminal through javascript, the details are as follows:
:
Implementation Code:
Touchstart, touchmove, touchend, touchcancel
Script // get the node var block = document. getElementById ("block"); var oW, oH; // bind the touchstart event block. addEventListener ("touchstart", function (e) {console. log (e); var touches = e. touches [0]; oW = touches. clientX-block. offsetLeft; oH = touches. clientY-block. offsetTop; // The default event document that prevents page sliding. addEventListener ("touchmove", defaultEvent, false) ;}, false) block. addEventListener ("touchmove", function (e) {var touches = e. touches [0]; var oLeft = touches. clientX-oW; var oTop = touches. clientY-oH; if (oLeft <0) {oLeft = 0;} else if (oLeft> document.doc umentElement. clientWidth-block. offsetWidth) {oLeft = (document.doc umentElement. clientWidth-block. offsetWidth);} block. style. left = oLeft + "px"; block. style. top = oTop + "px" ;}, false); block. addEventListener ("touchend", function () {document. removeEventListener ("touchmove", defaultEvent, false) ;}, false); function defaultEvent (e) {e. preventDefault ();} script
The above is all the content of this article, and I hope it will help you learn javascript programming.