-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParallaxHeader.jsx
99 lines (90 loc) · 2.85 KB
/
ParallaxHeader.jsx
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React from "react";
// nodejs library that concatenates classes
import classNames from "classnames";
// nodejs library to set properties for components
import PropTypes from "prop-types";
// @material-ui/core components
import withStyles from "@material-ui/core/styles/withStyles";
import Img from 'gatsby-image'
// core components
import parallaxStyle from "assets/components/parallaxStyle.jsx";
class ParallaxHeader extends React.Component {
constructor(props) {
super(props);
var windowScrollTop = typeof window !== 'undefined' && window.pageYOffset / 3;
this.state = {
transform: "translate3d(0," + windowScrollTop + "px,0)"
};
this.resetTransform = this.resetTransform.bind(this);
}
componentDidMount() {
var windowScrollTop = typeof window !== 'undefined' && window.pageYOffset / 3;
this.setState({
transform: "translate3d(0," + windowScrollTop + "px,0)"
});
window.addEventListener("scroll", this.resetTransform);
}
componentWillUnmount() {
window.removeEventListener("scroll", this.resetTransform);
}
resetTransform() {
var windowScrollTop = typeof window !== 'undefined' && window.pageYOffset / 3;
this.setState({
transform: "translate3d(0," + windowScrollTop + "px,0)"
});
}
render() {
const {
classes,
filter,
className,
children,
style,
image,
small,
medium
} = this.props;
const parallaxClasses = classNames({
[classes.parallax]: true,
[classes.filter]: filter,
[classes.small]: small,
[classes.medium]: medium,
[className]: className !== undefined
});
/*return (
<div
className={parallaxClasses}
style={{
...style,
backgroundImage: "url(" + require('/assets/img/bg1.jpg') + ")",
...this.state
}}
ref="parallax"
>
{children}
</div>
);*/
return (
<div className={parallaxClasses} style={{...style, ...this.state}} ref="parallax">
<Img fluid={image}
style={{
position: "absolute",
left: 0,
top: 0,
width: "100%",
height: "100%",
}}/>
{children}
</div>
)
}
}
ParallaxHeader.propTypes = {
classes: PropTypes.object.isRequired,
className: PropTypes.string,
filter: PropTypes.bool,
children: PropTypes.node,
style: PropTypes.string,
image: PropTypes.object
};
export default withStyles(parallaxStyle)(ParallaxHeader);