参考 position()

position()

Sets the element's position.

The first two parameters, x and y, set the element's position relative to the top-left corner of the web page.

The third parameter, positionType, is optional. It sets the element's positioning scheme. positionType is a string that can be either 'static', 'fixed', 'relative', 'sticky', 'initial', or 'inherit'.

If no arguments passed, as in myElement.position(), the method returns the element's position in an object, as in { x: 0, y: 0 }.

示例

语法

position()
position([x], [y], [positionType])

参数

x
Number:

x-position relative to top-left of window (optional)

y
Number:

y-position relative to top-left of window (optional)

positionType
String:

it can be static, fixed, relative, sticky, initial or inherit (optional)

Returns

Object: object of form `{ x: 0, y: 0 }` containing the element's position.
Notice any errors or typos? Please let us know. Please feel free to edit src/dom/dom.js and open a pull request!

相关参考