Skip to content

Commit

Permalink
Fix image scale on window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Corrêa committed Jul 15, 2019
1 parent a755666 commit 491e08f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-image-hotspots",
"version": "1.0.6",
"version": "1.0.7",
"description": "React component for rendering images with hotspots",
"main": "dist/ImageHotspots.js",
"files": [
Expand Down
11 changes: 11 additions & 0 deletions src/ImageHotspots.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ImageHotspots extends React.Component {
this.container = React.createRef()

this.onImageLoad = this.onImageLoad.bind(this)
this.onWindowResize = this.onWindowResize.bind(this)
this.zoom = this.zoom.bind(this)
}

Expand All @@ -32,6 +33,12 @@ class ImageHotspots extends React.Component {
const orientation = (width > height) ? 'landscape' : 'portrait'

this.setState({ container: { width, height, orientation } })

window.addEventListener('resize', this.onWindowResize)
}

componentWillUnmount () {
window.removeEventListener('resize', this.onWindowResize)
}

render () {
Expand Down Expand Up @@ -150,6 +157,10 @@ class ImageHotspots extends React.Component {
}))
}

onWindowResize () {
this.zoom(this.state.image.scale)
}

zoom (scale) {
if (scale > 0) {
const { container, image } = this.state
Expand Down

0 comments on commit 491e08f

Please sign in to comment.