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,
|
2018-10-24 21:34:41 +13:00
|
|
|
url: null
|
2018-10-24 21:15:57 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillMount(){
|
|
|
|
|
if (this.props.image){
|
|
|
|
|
this.loadImage(this.props.image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps){
|
2018-10-24 21:34:41 +13:00
|
|
|
if (nextProps.image != this.state.url){
|
2018-10-24 21:15:57 +13:00
|
|
|
this.loadImage(nextProps.image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadImage(url){
|
2018-10-24 21:34:41 +13:00
|
|
|
|
|
|
|
|
// Reset our image to nothing
|
|
|
|
|
// This is needed when navigating to new view, but not unmounting the current components
|
|
|
|
|
// ie one artist to another
|
|
|
|
|
this.setState({
|
|
|
|
|
loaded: false,
|
|
|
|
|
url: null
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-24 21:15:57 +13:00
|
|
|
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
|
|
|
|
2018-10-24 21:34:41 +13:00
|
|
|
var style = {};
|
|
|
|
|
if (this.state.loaded && this.state.url){
|
|
|
|
|
style = {backgroundImage: 'url('+this.state.url+')'};
|
|
|
|
|
}
|
|
|
|
|
|
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:34:41 +13:00
|
|
|
<div className="parallax__image" style={style}></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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|