@@ -96,19 +96,21 @@ export class Pannable extends Etch {
96
96
}
97
97
98
98
readAfterUpdate ( ) {
99
- this . containerRect =
100
- this . element . getElementsByClassName ( 'ink-pannable' ) [ 0 ] . getBoundingClientRect ( )
99
+ this . innerContainerRect = this . refs . innerContainer . getBoundingClientRect ( )
100
+ this . outerContainerRect = this . refs . outerContainer . getBoundingClientRect ( )
101
+
101
102
this . setInitialScale ( this . item )
103
+
102
104
etch . update ( this )
103
105
}
104
106
105
107
setInitialScale ( item ) {
106
108
this . initialScale = 1
107
- if ( item . naturalHeight && item . naturalWidth && this . containerRect ) {
109
+ if ( item . naturalHeight && item . naturalWidth && this . outerContainerRect ) {
108
110
// only scale down, not up:
109
111
this . initialScale = Math . min (
110
- this . containerRect . width / item . naturalWidth ,
111
- this . containerRect . height / item . naturalHeight ,
112
+ this . outerContainerRect . width / item . naturalWidth ,
113
+ this . outerContainerRect . height / item . naturalHeight ,
112
114
1
113
115
)
114
116
}
@@ -136,14 +138,14 @@ export class Pannable extends Etch {
136
138
137
139
this . scale *= zoom
138
140
139
- if ( this . containerRect ) {
141
+ if ( this . innerContainerRect ) {
140
142
let x , y
141
143
if ( amount ) {
142
- x = this . containerRect . width / 2
143
- y = this . containerRect . height / 2
144
+ x = this . innerContainerRect . width / 2
145
+ y = this . innerContainerRect . height / 2
144
146
} else {
145
- x = clamp ( e . clientX - this . containerRect . left , 0 , this . containerRect . width )
146
- y = clamp ( e . clientY - this . containerRect . top , 0 , this . containerRect . height )
147
+ x = clamp ( e . clientX - this . innerContainerRect . left , 0 , this . innerContainerRect . width )
148
+ y = clamp ( e . clientY - this . innerContainerRect . top , 0 , this . innerContainerRect . height )
147
149
}
148
150
149
151
this . left -= x * zoom - x
@@ -191,8 +193,9 @@ export class Pannable extends Etch {
191
193
onmouseleave = { e => this . dragging = false }
192
194
onmousemove = { e => this . ondrag ( e ) }
193
195
onmousewheel = { e => this . zoom ( e ) }
194
- ondblclick = { e => this . resetAll ( ) } >
195
- < div style = { style } className = 'ink-pannable' >
196
+ ondblclick = { e => this . resetAll ( ) }
197
+ ref = 'outerContainer' >
198
+ < div style = { style } className = 'ink-pannable' ref = 'innerContainer' >
196
199
{ toView ( this . item ) }
197
200
</ div >
198
201
</ div > ;
0 commit comments