Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:12:31+00:00 2026-06-01T02:12:31+00:00

I’m in need of a function that figures out if the user is clicking,

  • 0

I’m in need of a function that figures out if the user is clicking, double-clicking or dragging the mouse.

Since it’s all happening in the same canvas using the normal events doesn’t work. I found this through google:

It is inadvisable to bind handlers to both the click and dblclick
events for the same element. The sequence of events triggered varies
from browser to browser, with some receiving two click events and
others only one. If an interface that reacts differently to single-
and double-clicks cannot be avoided, then the dblclick event should be
simulated within the click handler. We can achieve this by saving a
timestamp in the handler, and then comparing the current time to the
saved timestamp on subsequent clicks. If the difference is small
enough, we can treat the click as a double-click.

How could I achieve this in a good way?

First see if the click is pressed (for drag)? When it is released treat it as a click? and then if clicked again doubleclick?

How can I translate this to code? Help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:12:32+00:00Added an answer on June 1, 2026 at 2:12 am

    Something like the following should get you started, I’m using jQuery just to make it easier to show, this can be implemented with straight JS, it’s just a lot of noise

    $(function() {
    
      var doubleClickThreshold = 50;  //ms
      var lastClick = 0;
      var isDragging = false;
      var isDoubleClick = false;
    
      $node = ("#mycanvas");
      $node.click(function(){
        var thisClick = new Date().getTime();
        var isDoubleClick = thisClick - lastClick < doubleClickThreshold;
        lastClick = thisClick;
      });
    
      $node.mousedown(function() {
        mouseIsDown = true;
      });
    
      $node.mouseUp(function() {
        isDragging = false;
        mouseIsDown = false;
      });
    
      // Using document so you can drag outside of the canvas, use $node
      // if you cannot drag outside of the canvas
      $(document).mousemove(function() {
         if (mouseIsDown) {
           isDragging = true;
         }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.