# offset

获取匹配元素在当前窗口(左上角)的相对偏移,以像素计。此方法只对可见元素有效。

import { offset } from '@hui-pro/utils';
offset(node);

# API

参数 说明 类型 默认值 可选值
node DOM 元素节点 Element - -
container 可选 容器元素,若传入容器元素,获取到容器元素左上角的相对位置 Element document.body -

# return 返回内容

  • top: 元素上边到窗口上边的距离;
  • right: 元素右边到窗口左边的距离;
  • bottom: 元素下边到窗口上边的距离;
  • left: 元素左边到窗口左边的距离;