The example in this article describes how jQuery implements long-press button triggering events. Share it with everyone for your reference. The specific analysis is as follows:
The rapid development of mobile phones now requires many mobile phone gestures to be made into mobile web pages
There are many long-press button plug-ins on the Internet, and even jQuery Mobile has long-press events
But due to various compatibility issues,
Only use jquery to implement the long press action, which can maintain strong compatibility between mobile phones and computers
1. Basic goals
Create a button, which is essentially a layer with a gray background of 100x100px. If you press and hold it for 2 seconds, the text in the layer will change from in to out. As shown below:
2. Production process
The code is as follows:
Theoretically, to determine the end of a long press, just set the mouseup action on the mobile phone,
However, only setting mouseup on PC will have the following bugs:
Dark the text on the layer while long pressing, and then drag the mouse out of the layer, you can avoid the system mouseup judgment. Of course, this action cannot be realized on the mobile phone. If it is completely written to For web pages on mobile phones, this step can be completely ignored. However, for better compatibility, the mouseout action is added to correct this bug.
I hope this article will be helpful to everyone’s jQuery programming.