/
index.js
60 lines (49 loc) · 1.56 KB
/
index.js
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
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Scene } from 'scrollmagic'
import styles from './styles.module.scss'
export default class ScrollMagicExample extends PureComponent {
static contextTypes = {
scrollmagic: PropTypes.any,
}
static propTypes = {
children: PropTypes.any,
}
componentDidMount() {
// How to retrieve variables from scss in Javascript
console.log(styles['break-medium'])
console.log(styles['break-large'])
console.log(styles['break-xlarge'])
console.log(styles['nav-menu-break'])
this.animation = new TimelineMax({ paused: true })
.fromTo(this.node, 5, { opacity: 0 }, { opacity: 1 })
this.animation.play()
this.scrollAnim = new TimelineMax({ paused: true })
.fromTo(this.title, 5, { opacity: 0, y: 50 }, { opacity: 1, y: 0 })
this.scene = new Scene({ triggerElement: this.title, triggerHook: 0.4 })
this.scene.indicatorName = 'Test'
this.scene.on('enter', () => this.scrollAnim.play())
if (process.env.NODE_ENV === 'development') {
this.scene.addIndicators({ name: this.scene.indicatorName })
}
this.scene.addTo(this.context.scrollmagic)
}
// Binding
refNode = (c) => {
this.node = c
}
refTitle= (c) => {
this.title = c
}
render() {
const { children } = this.props
return (
<div ref={this.refNode} className={styles.text}>
{children}
<div style={{ marginTop: 300, height: 3000 }} ref={this.refTitle}>
<h1>HELLLO SCROLLMAGIC!</h1>
</div>
</div>
)
}
}