Special Note: I blog part of the reference network other blogs, but I have personally written and verified through. If you find that the blog has errors, please prompt to avoid misleading other people, thank you! Welcome reprint, but remember to indicate the source of the article: HTTP://WWW.CNBLOGS.COM/MAO2080/1, problem description
Recently in doing H5 video player, there are such needs: Click on the video playback interface can: Pause/play, double-click the video can: Full screen/exit full screen, but also binding click and DblClick will have a conflict, double click on each time will be executed two times click, Once DblClick this clearly does not meet the requirements, so on the Internet to find solutions.
2, solve the idea
The code to add an event is simple, in two ways:
- $ ("abc"). Bind ({"Click": FN, "DblClick": fn});
- $ ("abc"). Click (FN). DblClick (FN)
The problem with this is that you can just click on the function that you clicked, or not, so why?
Let's talk about the double-click mechanism:
Double-click (DblClick) The process is: Mousedown,mouseout,click,mousedown,mouseout,click,dblclick;
To implement a double-click we have to block these two clicks, so we set a timer in the click and delay the execution of the function.
3. Sample Code
1 var_time =NULL;2$( This). Find ("tr"). DblClick (function(e) {3 cleartimeout (_time);4Console.log ("DblClick");5 //true Double-click Code6 7}). Click (function(e) {8 cleartimeout (_time);9_time = SetTimeout (function(){TenConsole.log ("click"); One //Click the event here A -}, 300); -});4. Reference website http://www.cnblogs.com/huangjacky/archive/2012/09/27/2706110.html
"Go" jQuery-add both click and DblClick events