位置无法正常工作

时间:2012-04-30 10:22:40

标签: javascript jquery html

我需要在桌面左上角点0:0。

现在,从首页测量鼠标的位置

   <h2>
        TestPosition</h2>
    <table cellpadding="0" id="target" cellspacing="0" width="602" height="500" style="float: left;
        margin: 0px; padding: 0px; position: relative; background: url(/content/games/kamikaze2/back.jpg) no-repeat 0 0;">
    </table>
    <div id="log">
    </div>
    <script type="text/javascript">
        $("#target").mousemove(function (event) {
            var thisPosX = $(this).position().left;
            var thisPosY = $(this).position().top;

            var relX = (event.clientX - thisPosX);
            var relY = (event.clientY - thisPosY);

            var msg = "Handler for .mousemove() called at ";
            msg += relX + ", " + relY;
            $("#log").html("<div>" + msg + "</div>");
        });
    </script>

enter image description here

1 个答案:

答案 0 :(得分:1)

没有

function localMouse(event, element)
{
    var offset = $(element).offset();
    return [event.pageX - offset.left, event.pageY - offset.top];
}