useElementBounding
useElementBounding
HTML要素のリアクティブなバウンディングボックス
使用法
<script setup lang="ts">
import { useElementBounding } from '@vueuse/core'
import { useTemplateRef } from 'vue'
const el = useTemplateRef('el')
const { x, y, top, right, bottom, left, width, height } = useElementBounding(el)
</script>
<template>
<div ref="el" />
</template>
コンポーネントの使用法
<template>
<UseElementBounding v-slot="{ width, height }">
Width: {{ width }} Height: {{ height }}
</UseElementBounding>
</template>
ディレクティブの使用法
<script setup lang="ts">
import { vElementBounding } from '@vueuse/components'
interface BoundingType {
height: number
bottom: number
left: number
right: number
top: number
width: number
x: number
y: number
}
function onBounding({ height, bottom, left, right, top, width, x, y }: BoundingType) {
console.log(height, bottom, left, right, top, width, x, y)
}
const options = {
reset: true,
windowResize: true,
windowScroll: true,
immediate: true,
updateTiming: 'sync',
}
</script>
<template>
<textarea v-element-bounding="onBounding" />
<!-- オプション付き -->
<textarea v-element-bounding="[onBounding, options]" />
</template>
© 2019–PRESENT Anthony Fu https://github.com/antfu
※このページは Nuxt.js 公式ドキュメントの翻訳ページです。
公式ドキュメントの該当ページはこちら:
#