Search the web
Sign In
New User? Sign Up
canvas-developers · Canvas Developers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Best way to allow for clicks? Collision detection? Events?   Message List  
Reply | Forward Message #465 of 493 |
Re: [canvas-developers] Best way to allow for clicks? Collision detection? Events?

> If I have ui elements in a canvas that I want to be clickable - what
> is the best way to go about doing that? Do I need to create some kind
> of collision detection to see if the mouse x,y is in a region? Or is
> there some better way?

You can:

1. Attach a function to the canvas onclick event
2. Get the mouse coords from the resultant event object.
3. Those, combined with some magic, will help you get the position of
the mouse cursor.

Below is a function which I use. If nested within a TABLE though, it
doesn't seem to work. :-( Any amount of DIV nesting does though. You
can see it in action here: http://dev.rgraph.org The top graph has
clickable bars.

http://www.phpguru.org/downloads/mousecoords.txt

--
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)



Wed Nov 12, 2008 5:48 pm

richard.heyes@...
Send Email Send Email

Forward
Message #465 of 493 |
Expand Messages Author Sort by Date

If I have ui elements in a canvas that I want to be clickable - what is the best way to go about doing that? Do I need to create some kind of collision...
Andrew
triptych999
Offline Send Email
Nov 12, 2008
3:59 pm

... You can: 1. Attach a function to the canvas onclick event 2. Get the mouse coords from the resultant event object. 3. Those, combined with some magic, will...
Richard Heyes
richard.heyes@...
Send Email
Nov 12, 2008
5:48 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help