import{o as s,a as e,y as n}from"./vue-libs.b44bc779.js";const a={class:"van-doc-markdown-body"},o=n(`

useRect

Intro

Get the size of an element and its position relative to the viewport, equivalent to Element.getBoundingClientRect.

Usage

Basic Usage

<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 };
  },
};

API

Type Declarations

function useRect(
  element: Element | Window | Ref<Element | Window | undefined>
): DOMRect;

Return Value

NameDescriptionType
widthWidth of the elementnumber
heightHeight of the elementnumber
topThe distance from the top to the top-left of the viewportnumber
leftThe distance from the left to the top-left of the viewportnumber
rightThe distance from the right to the top-left of the viewportnumber
bottomThe distance from the bottom to the top-left of the viewportnumber
`,7),l=[o],h={__name:"use-rect.en-US",setup(d,{expose:t}){return t({frontmatter:{}}),(c,p)=>(s(),e("div",a,l))}};export{h as default};