PP.calculateMouseCoords

Syntax

calculateMouseCoords(event);

Parameters

event. Mouse event.

Description

The calculateMouseCoords method calculates current coordinates of the mouse cursor.

Comments

This method returns a JSON object with the following fields: X - abscissa, Y - ordinate of the current mouse cursor position.

Example

To execute the example, the HTML page must contain links to the PP.js scenario file and the PP.css styles file. Create a text area, handle event of clicking on this area and show current coordinates of the mouse cursor in the area:

// Create a text area
var textArea = new PP.Ui.TextArea({
    ParentNode: document.body,
    Width: 250,
    Height: 100,
});
// Process the Click event
textArea.Click.add(function (sender, args) {
    if (PP.isDownOn(textArea.getDomNode(), args.Event)) {
        // Determine the current mouse coordinates if the cursor is above the text area
        var coord = PP.calculateMouseCoords(args.Event);
        textArea.setContent("Current mouse coordinates: (" + coord.X + ", " + coord.Y + ")");
    };
});

After executing the example a text area is created and placed in the page. On clicking on this area it shows current cursor coordinates:

See also:

PP