File size: 1,744 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { useRef } from 'react'
import { Switch, Route, Link } from 'wouter'
import { Parallax, ParallaxLayer, IParallax } from '../../src'
import './App.css'

interface BaseDemoProps {
  horizontal?: boolean
}

const BaseDemo = ({ horizontal = false }: BaseDemoProps) => {
  const parallax = useRef<IParallax>(null)

  const scroll = (to: number) => {
    if (parallax.current) {
      parallax.current.scrollTo(to)
    }
  }

  return (
    <Parallax
      ref={parallax}
      pages={3}
      horizontal={horizontal}
      data-testid="container"
      className="container"
    >
      <ParallaxLayer
        horizontal={!horizontal}
        offset={1}
        speed={1}
        data-testid="opposite-layer"
        className="opposite"
      />

      <ParallaxLayer
        offset={1}
        speed={1}
        data-testid="default-layer"
        className="default"
      />

      <ParallaxLayer
        sticky={{ start: 1, end: 2 }}
        data-testid="sticky-layer"
        className="sticky"
      >
        <div className="sticky-content flex-center">Sticky</div>
      </ParallaxLayer>

      <ParallaxLayer className="flex-center">
        <button onClick={() => scroll(1)}>Scroll</button>
      </ParallaxLayer>
    </Parallax>
  )
}

function App() {
  return (
    <Switch>
      <Route path="/">
        <h1>Parallax Test Demos</h1>
        <div style={{ display: 'flex', flexDirection: 'column' }}>
          <Link href="/vertical">Vertical</Link>
          <Link href="/horizontal">Horizontal</Link>
        </div>
      </Route>
      <Route path="/vertical">
        <BaseDemo />
      </Route>
      <Route path="/horizontal">
        <BaseDemo horizontal />
      </Route>
    </Switch>
  )
}

export default App