复制代码代码如下: element.addEventListener("MSGestureHold", handleHold); function handleHold(evt) { if (evt.detail evt.MSGESTURE_FLAG_BEGIN) { // Begin signals the start of a gesture. For the Hold gesture, this means the user has been holding long enough in place that the gesture will become a complete press hold if the finger is lifted. } if (evt.detail evt.MSGESTURE_FLAG_END) { // End signals the end of the gesture. } if (evt.detail evt.MSGESTURE_FLAG_CANCEL) { // Cancel signals the user started the gesture but cancelled it. For hold, this occurs when the user drags away before lifting. This flag is sent together with the End flag, signaling the gesture recognition is complete. } }
复制代码代码如下: targetElement.addEventListener("MSGestureChange", manipulateElement); function manipulateElement(e) { // Uncomment the following code if you want to disable the built-in inertia provided by dynamic gesture recognition // if (e.detail == e.MSGESTURE_FLAG_INERTIA) // return; var m = new MSCSSMatrix(e.target.style.transform); // Get the latest CSS transform on the element e.target.style.transform = m .translate(e.offsetX, e.offsetY) // Move the transform origin under the center of the gesture .rotate(e.rotation * 180 / Math.PI) // Apply Rotation .scale(e.scale) // Apply Scale .translate(e.translationX, e.translationY) // Apply Translation .translate(-e.offsetX, -e.offsetY); // Move the transform origin back }