Skip to content

v-blur

Add background blur overlay effect to elements.

Since: 1.5.0

Usage

Basic

vue
<template>
  <div v-blur="isBlurred">Background content</div>
</template>

<script setup>
import { ref } from 'vue'

const isBlurred = ref(false)
</script>

With Blur Radius

vue
<template>
  <div v-blur="15">15px blur radius</div>
</template>

With Options

vue
<template>
  <div v-blur="{
    visible: isBlurred,
    radius: 20,
    overlayColor: 'rgba(255, 255, 255, 0.3)',
    lockScroll: true
  }">
    Content
  </div>
</template>

API

Options

OptionTypeDefaultDescription
radiusnumber10Blur radius in pixels
visiblebooleantrueWhether to show blur effect
durationnumber300Transition duration in milliseconds
overlayColorstring'rgba(0, 0, 0, 0.5)'Overlay color
zIndexnumber999Overlay z-index
lockScrollbooleantrueWhether to lock scroll when active
classstring-Custom class name
onShow() => void-Callback when shown
onHide() => void-Callback when hidden

Binding Types

ts
type BlurBinding = boolean | number | BlurOptions

Composable

You can also use the useBlur composable:

vue
<script setup>
import { ref } from 'vue'
import { useBlur } from 'directix'

const containerRef = ref(null)
const { isVisible, show, hide, toggle, bind } = useBlur({
  radius: 15,
  onShow: () => console.log('Blur shown'),
  onHide: () => console.log('Blur hidden')
})

onMounted(() => bind(containerRef.value))
</script>

<template>
  <div ref="containerRef">
    <button @click="toggle">Toggle Blur</button>
  </div>
</template>

Composable API

Property/MethodTypeDescription
isVisibleRef<boolean>Current visibility state
show()() => voidShow blur effect
hide()() => voidHide blur effect
toggle()() => voidToggle visibility
bind(el)(element: HTMLElement) => () => voidBind to element, returns unbind function

Code Generator

Quick Code Generator
<template>
  <div v-blur="{ value: true, amount: 10 }">
    <!-- Add background blur overlay effect to elements. directive -->
  </div>
</template>

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

// Configure your options here
const options = { value: true, amount: 10 }
</script>

Released under the MIT License.