Capturing cursor position in javascript inline with element - Stack Overflow

I am trying to make a div popup next to the mouse when a table cell is hovered over.<td onmouseover=

I am trying to make a div popup next to the mouse when a table cell is hovered over.

<td onmouseover="bubblePopup("param1","param2");">This is the cell</td>

Is it possible to get the cursor position with my bubblePopup function.

function bubblePopup(param1, param2){
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', param1);

    newdiv.style.width = "200px";
    newdiv.style.height = "80px";

    newdiv.style.position = "absolute";
    newdiv.style.left = cursorX + "px";
    newdiv.style.top = cursorY + "px";

    newdiv.innerHTML = "content";
    document.body.appendChild(newdiv);
}

I would prefer native javascript(but will consider jquery options too). It only needs to work in Firefox 3.5 and up.

I am trying to make a div popup next to the mouse when a table cell is hovered over.

<td onmouseover="bubblePopup("param1","param2");">This is the cell</td>

Is it possible to get the cursor position with my bubblePopup function.

function bubblePopup(param1, param2){
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', param1);

    newdiv.style.width = "200px";
    newdiv.style.height = "80px";

    newdiv.style.position = "absolute";
    newdiv.style.left = cursorX + "px";
    newdiv.style.top = cursorY + "px";

    newdiv.innerHTML = "content";
    document.body.appendChild(newdiv);
}

I would prefer native javascript(but will consider jquery options too). It only needs to work in Firefox 3.5 and up.

Share Improve this question edited Feb 11, 2011 at 15:35 Mike asked Feb 11, 2011 at 15:25 MikeMike 2,90010 gold badges44 silver badges57 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I slapped together a fiddle that might get you on the right track.

http://www.jsfiddle/dduncan/WccJw/2/

(Edited to pretty it up slightly)

http://jsfiddle/CtCXE/

var td = document.getElementById("thetd");

td.onmouseover = function(e){bubblePopup(e, 'param1','param2')};

function bubblePopup(e, param1, param2){
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', param1);

    newdiv.style.width = 200;
    newdiv.style.height = 80;

    var cursorX = e.pageX,
        cursorY = e.pageY;

    newdiv.style.position = "absolute";
    newdiv.style.left = cursorX + 'px';
    newdiv.style.top = cursorY + 'px';

    newdiv.innerHTML = "content";
    document.body.appendChild(newdiv);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744397248a4572204.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信