useElementBounding
HTML要素のリアクティブな境界ボックス
デモ
変更を確認するにはボックスのサイズを変更してください
使用方法
vue
<script>
import { useElementBounding } from '@vueuse/core'
import { ref } from 'vue'
export default {
setup() {
const el = ref(null)
const { x, y, top, right, bottom, left, width, height }
= useElementBounding(el)
return {
el,
/* ... */
}
},
}
</script>
<template>
<div ref="el" />
</template>
コンポーネントの使用法
この関数は、
@vueuse/components
パッケージを介して、レンダーレスコンポーネントバージョンも提供します。詳細な使用方法はこちら。
vue
<template>
<UseElementBounding v-slot="{ width, height }">
Width: {{ width }} Height: {{ height }}
</UseElementBounding>
</template>
型宣言
型宣言を表示
typescript
export interface UseElementBoundingOptions {
/**
* Reset values to 0 on component unmounted
*
* @default true
*/
reset?: boolean
/**
* Listen to window resize event
*
* @default true
*/
windowResize?: boolean
/**
* Listen to window scroll event
*
* @default true
*/
windowScroll?: boolean
/**
* Immediately call update on component mounted
*
* @default true
*/
immediate?: boolean
/**
* Timing to recalculate the bounding box
*
* Setting to `next-frame` can be useful when using this together with something like {@link useBreakpoints}
* and therefore the layout (which influences the bounding box of the observed element) is not updated on the current tick.
*
* @default 'sync'
*/
updateTiming?: "sync" | "next-frame"
}
/**
* Reactive bounding box of an HTML element.
*
* @see https://vueuse.dokyumento.jp/useElementBounding
* @param target
*/
export declare function useElementBounding(
target: MaybeComputedElementRef,
options?: UseElementBoundingOptions,
): {
height: Ref<number, number>
bottom: Ref<number, number>
left: Ref<number, number>
right: Ref<number, number>
top: Ref<number, number>
width: Ref<number, number>
x: Ref<number, number>
y: Ref<number, number>
update: () => void
}
export type UseElementBoundingReturn = ReturnType<typeof useElementBounding>
ソース
貢献者
変更履歴
v12.0.0-beta.1
2024/11/21v11.0.0-beta.2
2024/7/17v10.7.1
2023/12/27v9.11.0
2023/1/17v9.10.0
2023/1/3