I'm trying to scale image double when click zoom-in button,
and half image when click zoom-out button
My issue is, when click zoom-in button (so, image size is double)
and if it's size over than container, the left side of image (or top side of image) cut off.
what should i do?
same question here, CSS Transform scale scrolling issue ... but it's not a good idea.
because it also scale focus on 'top-left side' when zoom-out
image, so center alignment is impossible
(i want to apply transform: scale(..) using transform-origin: center)
the only way that i know is every time calculate image size, and apply margin for cut-off, but it is hard to apply
any idea please?
code look like this.
constructor() {
super()
this._refs = {
ratio: 100
}
}
getImageStyle() {
return {
transform: scale(calc($ {
this.state.ratio
}
/ 100)),
'transform-origin': 'center'
}
}
zoomIn() {
this.setState({
ratio: this.state.ratio + 25
})
}
zoomIn() {
this.setState({
ratio: this.state.ratio - 25
})
}
render() {
const {
src
} = this.props
return ( <
div className = {
styles.wrapper
} <
img style = {
this.getImageStyle()
}
ref = {
(elem) => setRefToNode(this._refs, 'image', elem)
}
className = {
styles.image
}
src = {
src
}
/> <
/div>
)
}
.wrapper {
display: flex;
position: relative;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
overflow: scroll;
.image {
position: relative;
max-width: 100%;
max-height: 100%;
background-color: white;
}
}