Skip to content

Commit

Permalink
refactor: improve image loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
nzbin committed May 27, 2019
1 parent 10bb79d commit 593a368
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,37 +736,42 @@ Magnify.prototype = {
this.isRotated
);

// Remove class must when image setting end
this.$stage.removeClass('stage-ready');
this.$image.removeClass('image-ready');

// loader end
this.$magnify.find('.magnify-loader').remove();
// Just execute before image loaded
if(!this.imgLoaded){
// loader end
this.$magnify.find('.magnify-loader').remove();

// Remove class must when image setting end
this.$stage.removeClass('stage-ready');
this.$image.removeClass('image-ready');

// Add image init animation
if (this.options.initAnimation && !this.options.progressiveLoading) {
$image.fadeIn();
}

// Add image init animation
if (this.options.initAnimation && !this.options.progressiveLoading) {
$image.fadeIn();
this.imgLoaded = true;
}

},
loadImg: function (imgSrc, fn, err) {

var self = this;

var loaderHTML = '<div class="magnify-loader"></div>';
// Reset image
this.$image.removeAttr('style').attr('src', '');
this.isRotated = false;
this.rotateAngle = 0;

this.imgLoaded = false;

// loader start
this.$magnify.append(loaderHTML);
this.$magnify.append('<div class="magnify-loader"></div>');

// Add class before image loaded
this.$stage.addClass('stage-ready');
this.$image.addClass('image-ready');

// Reset image
this.$image.removeAttr('style').attr('src', '');
this.isRotated = false;
this.rotateAngle = 0;

if (this.options.initAnimation && !this.options.progressiveLoading) {
this.$image.hide();
}
Expand Down

0 comments on commit 593a368

Please sign in to comment.