Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Last active March 23, 2020 15:17
Show Gist options
  • Save mfbx9da4/fbc6a8c367b83d7330562c0fd10ae06b to your computer and use it in GitHub Desktop.
Save mfbx9da4/fbc6a8c367b83d7330562c0fd10ae06b to your computer and use it in GitHub Desktop.
import { Component } from 'react'
class OverlayDesign extends Component {
state = {
hide: true,
}
listener = event => {
if (event.keyCode === 74) {
this.setState({ hide: !this.state.hide })
}
}
componentDidMount() {
window.addEventListener('keydown', this.listener)
}
componentWillUnmount() {
window.removeEventListener('keydown', this.listener)
}
render() {
return (
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
zIndex: 99999999,
display: this.state.hide ? 'none' : 'block',
objectFit: 'cover',
}}
>
<img
style={{ width: '100%' }}
src={this.props.src}
alt={this.props.src}
/>
</div>
)
}
}
export default OverlayDesign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment