Skip to content

MercuryGryph/ParallaxBox

Repository files navigation

ParallaxBox

Kotlin Compose Multiplatform Maven Central

English | 中文

A Compose Multiplatform library that applies a parallax shift to layered content based on pointer (mouse / touch) position. Each layer can use a different response strategy — linear, inverse, accelerated, or custom.

example-1.gif

Quick Start

Quick Start

API

ParallaxBox

Parameter Default
modifier Modifier Outer container modifier
enterAnimation spring() Animation on pointer enter
exitAnimation enterAnimation Animation on pointer exit
passThroughPointerEvents false Propagate events to parent
content Builder for layer() calls

The content block is not @Composable — only layer() is valid inside.

LayerResponse

A fun interface mapping normalized pointer position (x, y each in [-1, 1]) to an Offset.

Factory Behavior
static() Always Offset.Zero — fixed reference
linear(sx, sy) Proportional to distance from center
inverse(sx, sy) Opposite direction
horizontal(s) Horizontal axis only
vertical(s) Vertical axis only
accelerated(sx, sy, power) Dramatic near edges

example-2.gif

Custom strategies:

layer(response = { (x, y) ->
    Offset(x * 20f, y * 5f)
}) { ... }

Details

Edge-Safe Layers

example-3.gif

By default, shifted layers expose the content underneath at the opposite edges. Set insets to the maximum expected offset to prevent this:

Details

Platforms

Desktop (JVM) · Android · iOS · Web (JS / WASM)

All platforms use the same API.

License

Apache License, Version 2.0

About

A Compose Multiplatform library that applies a parallax shift to layered content based on pointer (mouse / touch) position. Each layer can use a different response strategy — linear, inverse, accelerated, or custom.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages