Skip to content

Configuration

When installing the plugin, you can provide an options object to customize its behavior globally.

Global Options

presets

Define custom presets or override existing ones. A preset is essentially a mapping to a string of CSS classes (standard or Tailwind).

typescript
import { createApp } from 'vue'
import Viewport from '@vikeriait/vue-viewport'

const app = createApp(App)

app.use(Viewport, {
  presets: {
    // Override existing 'fade' with a slower, custom easing
    fade: 'opacity-0 transition-opacity duration-1000 ease-[cubic-bezier(0.25,1,0.5,1)] inviewport:opacity-100',

    // Add new custom preset 'rotate-in'
    // Starts rotated and transparent -> Becomes normal when in view
    'rotate-in':
      'rotate-180 opacity-0 transition-all duration-700 inviewport:rotate-0 inviewport:opacity-100',
  },
})

Once defined, you can use them immediately:

html
<div v-viewport="'rotate-in'">Spinning Entry!</div>

CSS Variables Reference

The library uses CSS variables to control the default behavior and timing of all animations. You can override these at the :root level for global changes, or within a specific selector for localized effects.

VariableDefaultDescription
--viewport-duration0.6sThe duration of the entry/leave transition.
--viewport-easeease-outThe timing function for the transition.
--viewport-delay0sThe base delay before the animation starts.
--viewport-stagger100msThe default delay between siblings when stagger is enabled.
--viewport-distance2remThe distance for movement-based presets (slide, fade-up, etc.).
--viewport-scale-in0.95The starting scale for the scale-up preset.
--viewport-scale-out1.05The starting scale for the scale-down preset.
--viewport-blur12pxThe starting blur amount for the blur-in preset.

Example Override

css
/* Change default speed and movement globally */
:root {
  --viewport-duration: 0.4s;
  --viewport-distance: 40px;
}

/* Specific section with slower, custom animations */
.hero-section {
  --viewport-duration: 1.2s;
  --viewport-ease: cubic-bezier(0.34, 1.56, 0.64, 1);
}