"Go" jQuery-add both click and DblClick events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.