Skip to content

Commit 5443868

Browse files
committed
c
1 parent 9fb57d7 commit 5443868

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/imageViewer/ImageView.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/imageViewer/sample/imageViewer.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ button {overflow: visible; width: auto; padding: 0; -moz-box-sizing: content-box
4343
.viewerC .rightH:hover .cr {background-position:-60px 0;}
4444
.viewerC .rightH:active .cr {background-position:-120px 0;}
4545
.viewerC .viewer {position:relative;height:100%;padding:0 70px;}
46-
.viewerC .imgBder {height:100%;width:100%;overflow:hidden;}
46+
.viewerC .imgBder {height:100%;width:100%;overflow:hidden;text-align:center;}
4747
.viewerC .imgBder.imgLoading {background:url(//s4.ksyun.com/i/4/006.png) no-repeat center}
4848
.viewerC .imgBder:before {content:''}
4949
.viewerC .imgBder:before {display:inline-block;width:0;height:100%;vertical-align:middle;}

0 commit comments

Comments
 (0)