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 7956767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:05:31+00:00 2026-06-04T04:05:31+00:00

I am playing with a simple tutorial for drawing line in HTML5 canvas. Since,

  • 0

I am playing with a simple tutorial for drawing line in HTML5 canvas. Since, it is based on jQuery, it is easy to add lots of effects to the drawing.

How can I make the point clickable/hoverable to add jquery effects upon click/hover (mouseenter/mouseleave)? The points are drawn by

c.fillStyle = '#333';

for(var i = 0; i < data.values.length; i ++) {
    c.beginPath();
    c.arc(getXPixel(i), getYPixel(data.values[i].Y), 4, 0, Math.PI * 2, true);
    c.fill();
}

How to add jquery selector? Basically, I want to show the point coordinates upon click or hover.

  • 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-04T04:05:32+00:00Added an answer on June 4, 2026 at 4:05 am

    The problem is that jQuery works with DOM and not drawings on canvas. What you need to do is to store those points somewhere and on hovering over the canvas element, check if the coordinates of the mouse relative to the canvas ( i.e. if you place the mouse over the top-left corner of the canvas, coords are [0,0] ) are within the area of the point/shape. If so, the point is hovered over by the mouse and you can display the effect.

    Psuedocode to understand better:

    // adding shapes to the canvas
    var shapes = [];  // make that rects for simplicity.
    For (condition):
        shapes.push ( new Rect(x,y,width,height) );
        canvas.rect( x, y, width, height );
    
    // testing hover.
    $("#canvas").mousemove(function(e) {
        var offsetX = e.pageX - $(this).position().left;
        var offsetY = e.pageY - $(this).position().top;
    
        Foreach shape in shapes:
            if( shape.contains(offsetX, offsetY) )    // a fictious method, implement it yourself...lookup for collision detection; not exactly that but something like that...
                Mouse hovers! do something great.
    });
    

    Ok, maybe to find out if a point is contained within a rectangle, you can use something like this:

    function contains(rect, x, y) {
        return (x >= rect.x &&
                x <= rect.x + rect.width &&
                y >= rect.y && 
                y <= rect.y + rect.height )
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with writing some simple Spring-based web apps and deploying them to
Playing with jquery for the first time, and I'm trying to get a simple
I am playing with SignalR and KnockoutJS and can't seem to find a simple
I am playing with a simple project based on Django framework. My IDE is
I am playing around with HTML 5 apps according to this tutorial: http://sixrevisions.com/web-development/html5-iphone-app/ It's
I was playing around making a simple haiku site using sqlalchemy and pylons. It
I have been playing around a bit with a fairly simple, home-made search engine,
I was playing around with recursion and did this simple function. I was assuming
So I have simple video tag on HTML 5 page playing OGG video. I
I am playing around with trying to make a simple Roguelike game to learn

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.