コンテンツにスキップ

**useParallax**

---- **視差効果**

カテゴリ
エクスポートサイズ
1.5 kB
最終更新日
先週

`useDeviceOrientation` を使用して視差効果を簡単に作成します。オリエンテーションがサポートされていない場合は、`useMouse` にフォールバックします。

デモ

roll: .nan
tilt: .nan
source: mouse
画像のクレジット:Jarom Vogel

使用方法

vue
<script setup>
import { useParallax } from '@vueuse/core'

const container = ref(null)
const { tilt, roll, source } = useParallax(container)
</script>

<template>
  <div ref="container" />
</template>

型宣言

typescript
export interface UseParallaxOptions extends ConfigurableWindow {
  deviceOrientationTiltAdjust?: (i: number) => number
  deviceOrientationRollAdjust?: (i: number) => number
  mouseTiltAdjust?: (i: number) => number
  mouseRollAdjust?: (i: number) => number
}
export interface UseParallaxReturn {
  /**
   * Roll value. Scaled to `-0.5 ~ 0.5`
   */
  roll: ComputedRef<number>
  /**
   * Tilt value. Scaled to `-0.5 ~ 0.5`
   */
  tilt: ComputedRef<number>
  /**
   * Sensor source, can be `mouse` or `deviceOrientation`
   */
  source: ComputedRef<"deviceOrientation" | "mouse">
}
/**
 * Create parallax effect easily. It uses `useDeviceOrientation` and fallback to `useMouse`
 * if orientation is not supported.
 *
 * @param target
 * @param options
 */
export declare function useParallax(
  target: MaybeElementRef,
  options?: UseParallaxOptions,
): UseParallaxReturn

ソース

ソースデモドキュメント

貢献者

Anthony Fu
Antério Vieira
Anthony Fu
huiliangShen
Jelf
wheat

変更履歴

v12.0.0-beta.1 2024年11月21日
0a9ed - feat!: Vue 2 サポートの削除、バンドルの最適化、クリーンアップ (#4349)
v10.8.0 2024年2月20日
3fd94 - feat: さまざまな画面の向きに対応可能 (#3675)

MITライセンスの下でリリースされています。