-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image flickers when updating src in Firefox #7
Comments
Very likely it's an existing bug: Images are flashing when updates by img.src[]=url in Firefox >= 8.0. Related: |
Yes, it's a bug in Firefox... shame that they did not fix it already. I have managed to find a workaround in my fork, basically adding another, temporary, invisible image to the DOM, forcing internal Firefox calculations and image pixel rendering, just before swapping with the real image, to prevent flicker. Something like this:
It uses jQuery, but maybe you can re-write it in pure javascript. Here is the demo: http://hnsmedia.net/zooming/ |
This kind of workaround by detecting user agent is not recommended and unreliable. |
I agree, but we can't do feature detection here since this is not a feature but a bug in Firefox, so this is the only way. Hopefully, |
Now it inserts a temporary hi-res image into the DOM (takes no space and invisible, removes it afterwards) before updating image src, for all browsers. This is a not pretty but reasonable fix. Thanks @daxhns for the suggestion. const parentNode = this.el.parentNode
const temp = this.el.cloneNode(false)
// Force compute the hi-res image in DOM to prevent
// image flickering while updating src
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() {
this.el.setAttribute('src', this.srcOriginal)
parentNode.removeChild(temp)
}.bind(this),
50
) |
Image blinks when changing src (for the first time) in OSX Firefox 50.0.2 and Android Firefox 50.0.2. The images do get preloaded though.
The text was updated successfully, but these errors were encountered: