Skip to content

v-parallax

Parallax scrolling effect.

Since: 1.5.0

Usage

Basic

vue
<template>
  <div v-parallax>Parallax content</div>
</template>

With Speed Factor

vue
<template>
  <div v-parallax="0.3">Slower parallax</div>
</template>

With Options

vue
<template>
  <div v-parallax="{
    speed: 0.5,
    reverse: true,
    mobileBreakpoint: 768
  }">
    Reverse parallax, disabled on mobile
  </div>
</template>

API

Options

OptionTypeDefaultDescription
speednumber0.5Parallax speed factor (0-1)
reversebooleanfalseReverse parallax direction
direction'vertical' | 'horizontal''vertical'Scroll direction
mobileBreakpointnumber768Disable below this width (0 = always enabled)
disabledbooleanfalseDisable parallax

Binding Types

ts
type ParallaxBinding = number | ParallaxOptions

Examples

Hero Section

vue
<template>
  <div class="hero" v-parallax="0.3">
    <h1>Welcome</h1>
    <p>Scroll down to see the effect</p>
  </div>
</template>

<style>
.hero {
  height: 100vh;
  background-image: url('hero-bg.jpg');
  background-size: cover;
}
</style>

Multiple Layers

vue
<template>
  <div class="parallax-container">
    <div v-parallax="0.1" class="layer layer-1">Background</div>
    <div v-parallax="0.3" class="layer layer-2">Middle</div>
    <div v-parallax="0.5" class="layer layer-3">Foreground</div>
  </div>
</template>

Composable API

For programmatic use, you can use the useParallax composable:

typescript
import { useParallax } from 'directix'

const { offset, progress, enabled, bind } = useParallax({
  speed: 0.5,
  reverse: false
})

// offset - current parallax offset in pixels
// progress - scroll progress (0-1)
// enabled - whether parallax is active

UseParallaxReturn

PropertyTypeDescription
offsetRef<number>Current parallax offset
progressRef<number>Scroll progress (0-1)
enabledRef<boolean>Whether parallax is active
bind(element: HTMLElement) => () => voidBind to element

Code Generator

Quick Code Generator
<template>
  <div v-parallax>
    <!-- Parallax scrolling effect. directive -->
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// Configure your options here
const options = {}
</script>

Released under the MIT License.