Home Reference Source Test Repository
public class | source

ElementRect

Provides the utilities for getting element's metrics.

Static Method Summary

Static Public Methods
public static

euclideanDistance(point1: {x: Number, y: Number}, point2: {x: Number, y: Number}): Number

Calculates euclidean distance between two points.

Constructor Summary

Public Constructor
public

constructor(element: HTMLElement): ElementRect

Initializes a new instance of the ElementRect class with the specified element.

Member Summary

Public Members
public get

boundingRect: ClientRect: *

Returns the size of the current element and its position relative to the viewport.

public get

center: {x: Number, y: Number}: *

Returns the center coordinates of the current element.

public

Returns the height of the current element.

public

Returns the size (the biggest side) of the current element.

public

Returns the width of the current element.

Method Summary

Public Methods
public

Determines if the specified point is contained within this element.

public

Calculates the distance between given point and farthest corner of the current element.

Static Public Methods

public static euclideanDistance(point1: {x: Number, y: Number}, point2: {x: Number, y: Number}): Number source

Calculates euclidean distance between two points.

Params:

NameTypeAttributeDescription
point1 {x: Number, y: Number}

Start point

point2 {x: Number, y: Number}

End point

Return:

Number

Distance between two points.

Public Constructors

public constructor(element: HTMLElement): ElementRect source

Initializes a new instance of the ElementRect class with the specified element.

Params:

NameTypeAttributeDescription
element HTMLElement

The DOM element to get metrics from

Return:

ElementRect

The new instance of a class.

Public Members

public get boundingRect: ClientRect: * source

Returns the size of the current element and its position relative to the viewport.

Return:

ClientRect

The returned value is a ClientRect object, which contains read-only left, top, right and bottom properties describing the border-box in pixels. top and left are relative to the top-left of the viewport.

public get center: {x: Number, y: Number}: * source

Returns the center coordinates of the current element.

Return:

{x: Number, y: Number}

Object containing coordinates of the element's center.

public height: Number source

Returns the height of the current element.

public size: number source

Returns the size (the biggest side) of the current element.

public width: Number source

Returns the width of the current element.

Public Methods

public contains(ev: Event | Object): Boolean source

Determines if the specified point is contained within this element.

Params:

NameTypeAttributeDescription
ev Event | Object

The object containing coordinates of the point.

ev.x Number

The x coordinate of the point.

ev.y Number

The y coordinate of the point.

ev.clientX Number

The x coordinate of the point.

ev.clientY Number

The y coordinate of the point.

Return:

Boolean

Returns true if the x and y coordinates of point is a point inside this element's rectangle, otherwise false.

public distanceToFarthestCorner(point: {x: Number, y: Number}): Number source

Calculates the distance between given point and farthest corner of the current element.

Params:

NameTypeAttributeDescription
point {x: Number, y: Number}
  • optional
  • default: {x:0,y:0}

The point object containing x and y coordinates.

Return:

Number

Distance from a point to the container's farthest corner.