开发者

How to get return value from mouse capturing function?

How to get return value from mouse capturing functi开发者_如何学Goon?

        function getMousePosition(e) 
        {
            positionX = e.pageX;
            positionY = e.pageY;

            if (positionX < 0){positionX = 0;}
            if (positionY < 0){positionY = 0;} 

            return positionX + " " + positionY;
        }

as in var mousePositions = getMousePosition(e);


 function getMousePosition(e)  
        { 
            e = e || event //for cross browser implentation
            var positionX = e.pageX; 
            var positionY = e.pageY; 

            if (positionX < 0){positionX = 0;} 
            if (positionY < 0){positionY = 0;}  

            return {positionX: positionX, positionY: positionY}; 
        } 

Now you can do this

var mousePositions = getMousePositions(someEventObject);

alert(mousePositions.positionX);
alert(mousePositions.positionY);


You have to assign the onmousemove Event-Listener to your function like in this expample:

document.onmousemove = getMousePosition();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜