@@ -100,22 +100,36 @@ define([], function() {
100100 this . options . movingCheck = ! ! this . options . movingCheck ;
101101 this . options . shiftWheelZoom = ! ! this . options . shiftWheelZoom ;
102102 newImg . src = this . img . src ;
103+ var loaded = false ;
104+ this . error = false ;
103105 if ( ! newImg . complete ) {
104- newImg . onload = newImg . onerror = function ( ) {
105- that . img . style . display = 'block' ;
106+ newImg . onload = function ( ) {
107+ if ( loaded ) return ;
108+ loaded = true ;
109+ that . img . style . display = 'inline-block' ;
106110 that . container = getParentElement ( img ) ;
107111 that . init ( ) ;
108112 that . bindEvts ( ) ;
109113 } ;
114+ newImg . onerror = function ( ) {
115+ if ( loaded ) return ;
116+ loaded = true ;
117+ // 出错时啥也不干了
118+ that . error = true ;
119+ that . img . style . display = 'inline-block' ;
120+ that . init ( ) ;
121+ that . img . style . visibility = 'visible' ;
122+ } ;
110123 var interval = setInterval ( function ( ) {
111124 if ( newImg . complete ) {
112125 clearInterval ( interval ) ;
113126 newImg . onload ( ) ;
114127 }
115128 } , 100 )
116129 } else {
130+ loaded = true ;
117131 setTimeout ( function ( ) {
118- that . img . style . display = 'block' ;
132+ that . img . style . display = 'inline- block' ;
119133 that . container = getParentElement ( img ) ;
120134 that . init ( ) ;
121135 that . bindEvts ( ) ;
@@ -150,6 +164,7 @@ define([], function() {
150164
151165 init : function ( ) {
152166 if ( this . options . onload ) this . options . onload ( ) ;
167+ if ( this . error ) return ;
153168 this . initPos = {
154169 x : 0 ,
155170 y : 0
@@ -232,10 +247,11 @@ define([], function() {
232247 } ,
233248
234249 scale : function ( scale , poi ) {
250+ if ( this . error ) return ;
235251 var w = this . w ;
236252 var h = this . h ;
237253 if ( this . zoom <= 20 && scale < 0 ) {
238- return ;
254+ return
239255 }
240256 w += w * scale * this . options . scaleNum ;
241257 h += h * scale * this . options . scaleNum ;
@@ -455,6 +471,7 @@ define([], function() {
455471 } ,
456472
457473 rotate : function ( deg ) {
474+ if ( this . error ) return ;
458475 this . center ( {
459476 x : 0 ,
460477 y : 0
0 commit comments