2

Let me try and be as much clear as possible although it won't be easy. OK, I have a circle inside div, and I know the x and y coordinates of the circle inside this div.

How could I create JavaScript or HTML tooltip to point at the spot where I clicked (in this case the circle)?

Here is the image so you can better understand what I'm trying to do:

Here is the picture

Now I know some of you will think: why not just use the id of circle and get the tooltip to point to that direction? Well because the circle is dynamically created as a JavaScript object and is not part of the HTML.

Because drawing saves time: where can I find a tooltip script pointing from above? Something like this, here goes another:

Screen shot

5
  • 1
    You should be able to programmatically add a click handler to the circle, when clicked you'd have access to the top/left values for the circle and should be able to instantiate whatever you need at the appropriate location. Not posting this as an answer as it's just a pointer to get you looking in a right direction. Commented Nov 11, 2009 at 13:49
  • Thank you Lazarus for your guidance, I can't add it because I didn't write rest of the code, and the time is short. Commented Nov 11, 2009 at 13:52
  • jvenema - Picasso made a bull with horns using bicycle parts and it turn out well, I just tried something similar, didn't went anywhere near as expected.. but it saves words Commented Nov 11, 2009 at 13:56
  • @c0mrade: like this? craigsworks.com/projects/qtip/demos/position/corner Commented Nov 11, 2009 at 14:17
  • I do like it, but I can't use any external libraries, because the person who made this code made it javascript with some prototype functions, I'm sure adding jquery will only complicate things. got anything else ? Commented Nov 11, 2009 at 14:19

3 Answers 3

3

If you're wondering about positioning the tooltip, use styling. Give the parent element relative position and the child absolute position in a style sheet:

#canvas {
    position: relative;
}
.tooltip {
    position: absolute;
}

When you create the tooltip, give it the 'tooltip' class and set its style.left and style.top properties. Try something like:

function click(evt) {
   if (! tooltip) {
       tooltip = document.createElement('div'); // or what-have-you
       tooltip.className += ' tooltip';
   ...
   tooltip.style.left = evt.offsetX + 'px';
   tooltip.style.left = evt.offsetY + 'px';
Sign up to request clarification or add additional context in comments.

Comments

1

You can capture the mouse position: http://www.codelifter.com/main/javascript/capturemouseposition1.html

Comments

0

Get the x and y coordinates when the mouse is clicked. Position the tooltip[probably will be a div] at the specified x and y coordinates.

To get the coordinates see

event.clientX and event.clientY

1 Comment

Thank you for your answer, I already have those values .. just looking how to position tooltip properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.