asyadiqin
asyadiqin

Reputation: 1667

How To Get DIV Coordinates Within HTML5 Canvas?

Is there a way for me to get the absolute position of a DIV element within a HTML5 Canvas element? Any help is greatly appreciated.

Upvotes: 1

Views: 982

Answers (1)

kanaka
kanaka

Reputation: 73091

noVNC (HTML5 VNC client) has some routines that can determine:

  • the actual position of a DOM element on a page: getPosition
  • the offset within that DOM element where a mouse click happened: getEventPosition

They should be fairly cross-browser.

You can use those as reference and that might help with your issue: http://github.com/kanaka/noVNC/blob/master/include/util.js#L121

Disclaimer: I made noVNC.

Upvotes: 2

Related Questions