import{o as s,a as e,y as n}from"./vue-libs.b44bc779.js";const a={class:"van-doc-markdown-body"},o=n(`
Get the size of an element and its position relative to the viewport, equivalent to Element.getBoundingClientRect.
<div ref="root" />
import { ref, onMounted } from 'vue';
import { useRect } from '@vant/use';
export default {
setup() {
const root = ref();
onMounted(() => {
const rect = useRect(root);
console.log(rect); // -> the size of an element and its position relative to the viewport
});
return { root };
},
};
function useRect(
element: Element | Window | Ref<Element | Window | undefined>
): DOMRect;
Name | Description | Type |
---|---|---|
width | Width of the element | number |
height | Height of the element | number |
top | The distance from the top to the top-left of the viewport | number |
left | The distance from the left to the top-left of the viewport | number |
right | The distance from the right to the top-left of the viewport | number |
bottom | The distance from the bottom to the top-left of the viewport | number |