Is there a built-in for long press event for metro apps? Possibly without using any external libraries such as jQuery.
Do you mean the tap-and-hold touch gesture? If so, the event is MSGestureHold, but you have to configure an MSGesture object to pick these up:
var gestureObject = new MSGesture();
gestureObject.target = divElement;
divElement.gestureObject = gestureObject;
divElement.addEventListener("pointerdown", pointerDown);
divElement.addEventListener("MSGestureHold", gestureHold);
function pointerDown(e) {
//Associate this pointer with the target's gesture
e.target.gestureObject.addPointer(e.pointerId);
}
function gestureHold(e) {
//Do what you need.
}
You use this same structure for MSGestureTap events as well as MSGestureStart, MSGestureChange, MSGestureEnd, and MSInertiaStart for other touch interactions. That is, having creating the MSGesture event and handled pointerdown to associate the pointer with the gesture, you can just add listeners for the other MSGesture* events as shown above for MSGestureHold.
I have a basic piece of code for this in the companion content for Chapter 12 of my second edition preview book (free from MSPress). It's a sample called PointerEvents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With