2016-10-25 17:01:37 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
|
|
|
|
|
export default class Parallax extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-10-25 17:01:37 +13:00
|
|
|
super(props);
|
2018-10-24 21:15:57 +13:00
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
loaded: false,
|
|
|
|
|
url: ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillMount(){
|
|
|
|
|
if (this.props.image){
|
|
|
|
|
this.loadImage(this.props.image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps){
|
|
|
|
|
if ((!this.state.url || nextProps.image != this.state.url ) && nextProps.image){
|
|
|
|
|
this.loadImage(nextProps.image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadImage(url){
|
|
|
|
|
var self = this;
|
|
|
|
|
var imageObject = new Image();
|
|
|
|
|
imageObject.src = url;
|
|
|
|
|
|
|
|
|
|
imageObject.onload = function(){
|
|
|
|
|
self.setState({
|
|
|
|
|
loaded: true,
|
|
|
|
|
url: url
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-25 17:01:37 +13:00
|
|
|
}
|
2018-09-17 08:18:07 +12:00
|
|
|
|
2018-10-23 21:54:08 +13:00
|
|
|
render(){
|
|
|
|
|
var class_name = "parallax";
|
|
|
|
|
if (this.props.blur){
|
|
|
|
|
class_name += " parallax--blur";
|
2018-08-27 08:21:41 +12:00
|
|
|
}
|
2018-10-24 21:15:57 +13:00
|
|
|
if (this.state.loaded){
|
|
|
|
|
class_name += " parallax--loaded";
|
|
|
|
|
}
|
2018-08-27 08:21:41 +12:00
|
|
|
|
2016-10-25 17:01:37 +13:00
|
|
|
return (
|
2018-10-23 21:54:08 +13:00
|
|
|
<div className={class_name}>
|
2018-10-24 21:15:57 +13:00
|
|
|
<div className="parallax__image" style={{backgroundImage: 'url('+this.state.url+')'}}></div>
|
2018-10-22 21:27:48 +13:00
|
|
|
<div className="parallax__overlay"></div>
|
2016-10-25 17:01:37 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-05-26 09:04:58 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|