---
title: "Advanced Parallax"
description: "Advanced Parallax carousel animation for React Native, with a live demo and its full source."
canonical_url: "https://rn-carousel.dev/Examples/custom-animations/advanced-parallax"
markdown_url: "https://rn-carousel.dev/Examples/custom-animations/advanced-parallax.md"
version: "5"
---
# Advanced Parallax

Check out the `advanced-parallax` animation demo for the full source code [here](https://github.com/dohooo/react-native-reanimated-carousel/blob/main/example/app/app/demos/custom-animations/advanced-parallax/index.tsx)

[Open the interactive advanced-parallax demo](https://rn-carousel.dev/Examples/custom-animations/advanced-parallax)

```tsx copy
import * as React from "react";
import { View } from "react-native";
import Animated, {
	Extrapolation,
	interpolate,
	interpolateColor,
	useAnimatedStyle,
} from "react-native-reanimated";
import type { SharedValue } from "react-native-reanimated";
import {
	Carousel,
	CarouselItemAnimation,
} from "react-native-reanimated-carousel";

import { SBItem } from "@/components/SBItem";
import { window } from "@/constants/sizes";
import { CaptureWrapper } from "@/store/CaptureProvider";

const PAGE_WIDTH = window.width;

interface ItemProps {
	index: number;
	relativeProgress: SharedValue<number>;
}
const CustomItem: React.FC<ItemProps> = ({ index, relativeProgress }) => {
	const maskStyle = useAnimatedStyle(() => {
		const backgroundColor = interpolateColor(
			relativeProgress.value,
			[-1, 0, 1],
			["#000000dd", "transparent", "#000000dd"],
		);

		return {
			backgroundColor,
		};
	}, [relativeProgress]);

	return (
		<View style={{ flex: 1 }}>
			<SBItem
				rounded={false}
				key={index}
				index={index}
				style={{ borderRadius: 0 }}
			/>
			<Animated.View
				pointerEvents="none"
				style={[
					{
						position: "absolute",
						top: 0,
						left: 0,
						right: 0,
						bottom: 0,
					},
					maskStyle,
				]}
			/>
		</View>
	);
};
function Index() {
	const [isAutoPlay, setIsAutoPlay] = React.useState(false);

	const animationStyle: CarouselItemAnimation = React.useCallback(
		(value: number, index: number) => {
			"worklet";

			const zIndex = interpolate(
				value,
				value > 0 ? [0, 1] : [-1, 0],
				value > 0 ? [10, 20] : [-10, 0],
				Extrapolation.CLAMP,
			);
			const translateX = interpolate(
				value,
				[-2, 0, 1],
				[-PAGE_WIDTH, 0, PAGE_WIDTH],
			);

			return {
				transform: [{ translateX }],
				zIndex,
			};
		},
		[],
	);

	return (
		<View
			id="carousel-component"
			dataSet={{ kind: "custom-animations", name: "advanced-parallax" }}
		>
			<CaptureWrapper>
				<Carousel
					loop={false}
					autoplay={isAutoPlay}
					style={{ width: PAGE_WIDTH, height: 240 }}
					data={[...new Array(6).keys()]}
					renderItem={({ index, relativeProgress }) => {
						return (
							<CustomItem
								key={index}
								index={index}
								relativeProgress={relativeProgress}
							/>
						);
					}}
					itemAnimation={animationStyle}
					animation={{ type: "timing", duration: 1200 }}
				/>
			</CaptureWrapper>
		</View>
	);
}

export default Index;

```
