Skip to content

Commit

Permalink
Remove from <img> the srcset attribute if present to actually show hi…
Browse files Browse the repository at this point in the history
…-res image when zoomed-in

…and put it back when zoomed-out
  • Loading branch information
mahish committed Feb 19, 2018
1 parent 7d9d5ba commit 717b997
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions build/zooming.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ var target = {
this.el = el;
this.instance = instance;
this.srcThumbnail = this.el.getAttribute('src');
this.srcset = this.el.getAttribute('srcset');
this.srcOriginal = getOriginalSource(this.el);
this.rect = this.el.getBoundingClientRect();
this.translate = null;
Expand Down Expand Up @@ -515,20 +516,30 @@ var target = {

// Force compute the hi-res image in DOM to prevent
// image flickering while updating src
if (this.srcset) {
temp.setAttribute('srcset', '');
}
temp.setAttribute('src', this.srcOriginal);
temp.style.position = 'fixed';
temp.style.visibility = 'hidden';
parentNode.appendChild(temp);

// Add delay to prevent Firefox from flickering
setTimeout(function updateSrc() {
if (this.srcset) {
this.el.setAttribute('srcset', '');
}
this.el.setAttribute('src', this.srcOriginal);

parentNode.removeChild(temp);
}.bind(this), 50);
}
},
downgradeSource: function downgradeSource() {
if (this.srcOriginal) {
if (this.srcset) {
this.el.setAttribute('srcset', this.srcset);
}
this.el.setAttribute('src', this.srcThumbnail);
}
},
Expand Down
Loading

0 comments on commit 717b997

Please sign in to comment.