views:

75

answers:

3

I have a floating DIV with dynamic content like this

<div id="rollover" style="display:none;background:#ffff99;width:150px;position:absolute;z-index:9999">
    <div id="rollover_content" style="padding:4px;border:1px solid"></div>
</div>

Event handlers fetch relevant content and set the innerHTML of the inner DIV. How can I position the top/left of the div as close as possible to the mouse position?

jQuery is available on the page, if that helps.

Thanks

+1  A: 

Here you can see how to get mouse coordinates: http://docs.jquery.com/Tutorials:Mouse_Position

From there you can update div absolute positioning to whatever the coords are.

Dustin Laine
+1  A: 

I believe what you want is the jQuery UI Position plugin. More info here.

Peter Bailey
+1  A: 

Assuming e is the parameter in your event handler:

$("#rollover").css({left:e.pageX + "px", top:e.pageY + "px"});
Plynx