GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • DocsDocs
  • ExamplesExamples
  • AI KitAIAI KitAI
  • React
  • JS
  • Vue
  • AI
  • animate
  • Timeline sequences
  • animateLayout
  • animateView
  • scroll
  • Easing
  • drag

This view

  • Original page
  • New address

GeezerVison is showing motion.dev — styleEffect | Render motion values to elements | Motion

styleEffect applies the output of motion values to the .style attribute of one or more elements.

When these motion values update, the element will re-render once per frame during the render step of the frameloop.

const blur = motionValue(2)
const filter = transformValue(() => `blur(${blur.get()}px)`)

styleEffect("img", { filter })

In addition to regular styles, styleEffect supports:

  • Independent transforms (x, scaleY etc)

  • Default unit types (i.e use numbers like 100 instead of "100px")

  • CSS properties

Hold to confirmOpen example
Black Friday

Motion+ is 20% off until 30 Nov.

One payment, lifetime updates. Get every premium example, Motion UI and AI Kit for your coding agent.

Get 20% offGet 20% off

Usage

Import styleEffect from "motion":

import { styleEffect } from "motion"

styleEffect accepts an element, list of elements, or CSS selector, plus a map of motion values:

const opacity = motionValue(0.5)
const backgroundColor = motionValue("#00f")

styleEffect("div", { opacity, backgroundColor })

When any of the motion values update, the element(s) will re-render on the next animation frame:

opacity.set(1)
animate(backgroundColor, "rgba(34, 255, 0, 1)")

Each motion value can be applied to any number of styles, and any number of elements.

const progress = motionValue(0)

styleEffect("#progress", {
  opacity: progress,
  scaleX: progress
})

Any motion value can be provided, including those defined by mapValue and transformValue:

const blur = motionValue(2)
const filter = transformValue(() => `blur(${blur.get()}px)`)

styleEffect("img", { filter })

Cancel

styleEffect returns a cleanup function which, when called, will stop applying changes to the motion values to the element:

const width = motionValue("0px")
const cancel = styleEffect("#progress", { width })

cancel()
Motion+One payment
Lifetime updates
Professional animation toolkit

Animate faster with Motion+.

Unlock 550+ premium examples, Motion UI, AI Kit and private community access.

Examples
550+
Tutorials
110+
AI Kit
Included
Explore Motion+Explore Motion+
  1. 01attrEffect

    attrEffect() applies motion values to HTML element attributes.

  2. 02propEffect

    propEffect() applies motion values to JavaScript object properties, useful with libraries like Three.js.

  3. 03svgEffect

    svgEffect() applies motion values to SVG styles and attributes, including pathLength for draw animations.

  • Spring: Follow Cursor animation exampleSpring: Follow Cursor
  • Hold to confirm animation exampleHold to confirm

Motion is supported by

Motion Cloud members who help fund Motion’s open-source development.

Become a supporter
  • Meepo
  • AAriel Conti
  • Sean Bugeja
  • SStanislav Shilin
  • nimit
  • DDamián Navarro
  • electrinity
  • BBeto
  • AAbhishek
  • Joshosullivam
  • AAriel Rodribuez
  • CCNTNAI
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.