-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
George Gillams
committed
Feb 7, 2020
1 parent
8003068
commit b24d068
Showing
4 changed files
with
210 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { cssModules } from '../helpers/cssModules'; | ||
import STYLES from './blur-effect.scss'; | ||
|
||
const getClassName = cssModules(STYLES); | ||
|
||
class BlurEffectView extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.myRef = React.createRef(); | ||
this.mainScrollElement; | ||
this.mainScrollElementClone; | ||
} | ||
|
||
static propTypes = { | ||
className: PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
className: null, | ||
}; | ||
|
||
adjustCloneScroll = () => { | ||
if (!this.mainScrollElement || !this.mainScrollElementClone) { | ||
return; | ||
} | ||
const yValue = this.mainScrollElement.offsetTop - window.pageYOffset; | ||
this.mainScrollElementClone.style.transform = `translatey(${yValue}px)`; | ||
}; | ||
|
||
recreateBlurClone = () => { | ||
if (!this.mainScrollElement || !this.myRef || !this.myRef.current) { | ||
return; | ||
} | ||
|
||
const newMainScrollElementClone = this.mainScrollElement.cloneNode(true); | ||
newMainScrollElementClone.style.filter = 'blur(10px)'; | ||
newMainScrollElementClone.id += `_clone${Math.random(0, 10)}`; | ||
if (this.mainScrollElementClone) { | ||
this.myRef.current.removeChild(this.mainScrollElementClone); | ||
} | ||
this.mainScrollElementClone = newMainScrollElementClone; | ||
this.myRef.current.append(this.mainScrollElementClone); | ||
this.adjustCloneScroll(); | ||
}; | ||
|
||
componentDidMount() { | ||
this.mainScrollElement = document.getElementById('mainScrollView'); | ||
this.recreateBlurClone(); | ||
this.interval = setInterval(this.recreateBlurClone, 2000); | ||
window.addEventListener('scroll', e => { | ||
this.adjustCloneScroll(); | ||
}); | ||
} | ||
|
||
render() { | ||
const { className, ...rest } = this.props; | ||
|
||
return ( | ||
<div | ||
ref={this.myRef} | ||
aria-hidden="true" | ||
className={getClassName('blur-effect__outer', className)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default BlurEffectView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import '~bpk-mixins'; | ||
@import '../Tokens/common'; | ||
|
||
.blur-effect { | ||
&__outer { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: -1; | ||
overflow: hidden; | ||
pointer-events: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters