@@ -77,14 +77,22 @@ export class Pannable extends Etch {
77
77
this . left = 0
78
78
this . top = 0
79
79
80
+ this . isLoaded = false
81
+
80
82
// force update, so readAfterUpdate gets executed
81
83
this . update ( )
82
- item . onload = ( ) => {
83
- etch . update ( this ) . then ( ( ) => {
84
- this . setInitialScale ( item )
85
- etch . update ( this )
86
- } )
84
+ if ( item && item . nodeName && item . nodeName . toLowerCase ( ) === 'img' ) {
85
+ item . onload = ( ) => {
86
+ etch . update ( this ) . then ( ( ) => {
87
+ this . setInitialScale ( item )
88
+ this . isLoaded = true
89
+ etch . update ( this )
90
+ } )
91
+ }
92
+ } else {
93
+ this . isLoaded = true
87
94
}
95
+ this . update ( )
88
96
}
89
97
90
98
readAfterUpdate ( ) {
@@ -120,7 +128,7 @@ export class Pannable extends Etch {
120
128
}
121
129
122
130
zoom ( e , amount ) {
123
- const zoom = amount || Math . pow ( 0.99 , e . deltaY )
131
+ const zoom = amount || Math . pow ( e . shiftKey ? 0.99 : 0.999 , e . deltaY )
124
132
125
133
if ( zoom * this . scale > this . maxScale || zoom * this . scale < this . minScale ) return
126
134
@@ -160,14 +168,19 @@ export class Pannable extends Etch {
160
168
this . toolbar = this . toolbar . concat ( this . item . toolbar )
161
169
}
162
170
163
- let position = { position :'relative' , height :'inherit' , width :'inherit' , transformOrigin : '0px 0px' }
171
+ let style = { position :'relative' , height :'inherit' , width :'inherit' , transformOrigin : '0px 0px' }
164
172
165
173
if ( this . zoomstrategy == 'width' ) {
166
- position . transform = 'translate(' + this . left + 'px,' + this . top + 'px)'
167
- position . height = scale
168
- position . width = scale
174
+ style . transform = 'translate(' + this . left + 'px,' + this . top + 'px)'
175
+ style . height = scale
176
+ style . width = scale
169
177
} else if ( this . zoomstrategy == 'transform' ) {
170
- position . transform = 'translate(' + this . left + 'px,' + this . top + 'px) scale(' + this . scale + ')'
178
+ style . transform = 'translate(' + this . left + 'px,' + this . top + 'px) scale(' + this . scale + ')'
179
+ }
180
+ if ( this . isLoaded ) {
181
+ style . visibility = 'initial'
182
+ } else {
183
+ style . visibility = 'hidden'
171
184
}
172
185
173
186
return < div style = { { height :'100%' , width :'100%' } }
@@ -177,7 +190,7 @@ export class Pannable extends Etch {
177
190
onmousemove = { e => this . ondrag ( e ) }
178
191
onmousewheel = { e => this . zoom ( e ) }
179
192
ondblclick = { e => this . resetAll ( ) } >
180
- < div style = { position } className = 'ink-pannable' >
193
+ < div style = { style } className = 'ink-pannable' >
181
194
{ toView ( this . item ) }
182
195
</ div >
183
196
</ div > ;
0 commit comments