Builtin Events
- invoke(type, more) — Invoke a class event, notifying all listeners. You must declare the events your class invokes when you install it; see @{function:JX.install} for documentation. Any arguments you provide will be passed to listener callbacks.
- static listen(type, callback) — Static listen interface for listening to events produced by any instance of this class. See @{method:listen} for documentation.
Querying Positions and Dimensions
- construct(x, y) — Construct a vector, either from explicit coordinates or from a node or event. You can pass two Numbers to construct an explicit vector:
- static getPos(node) — Determine where in a document an element is (or where an event, like a click, occurred) by building a new vector containing the position of a Node or @{class:JX.Event}. The 'x' component of the vector will correspond to the pixel offset of the argument relative to the left edge of the document, and the 'y' component will correspond to the pixel offset of the argument relative to the top edge of the document. Note that all vectors are generated in document coordinates, so the scroll position does not affect them.
- static getDim(node) — Determine the width and height of a node by building a new vector with dimension information. The 'x' component of the vector will correspond to the element's width in pixels, and the 'y' component will correspond to its height in pixels.
- static getScroll() — Determine the current scroll position by building a new vector where the 'x' component corresponds to how many pixels the user has scrolled from the left edge of the document, and the 'y' component corresponds to how many pixels the user has scrolled from the top edge of the document.
- static getViewport() — Determine the size of the viewport (basically, the browser window) by building a new vector where the 'x' component corresponds to the width of the viewport in pixels and the 'y' component corresponds to the height of the viewport in pixels.
- static getDocument() — Determine the size of the document, including any area outside the current viewport which the user would need to scroll in order to see, by building a new vector where the 'x' component corresponds to the document width in pixels and the 'y' component corresponds to the document height in pixels.
Changing Positions and Dimensions
- setPos(node) — Move a node around by setting the position of a Node to the vector's coordinates. For instance, if you want to move an element to the top left corner of the document, you could do this (assuming it has 'position: absolute'):
- setDim(node) — Change the size of a node by setting its dimensions to the vector's coordinates. For instance, if you want to change an element to be 100px by 100px:
Manipulating Vectors
- add(x, y) — Change a vector's x and y coordinates by adding numbers to them, or adding the coordinates of another vector. For example:
Other Methods
- static getAggregateScrollForNode(node) — Get the aggregate scroll offsets for a node and all of its parents.
- static getPosWithScroll(node) — Get the sum of a node's position and its parent scroll offsets.
- static initialize() — On initialization, the browser-dependent viewport root is determined and stored.