Skip to content
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

gif animation can not be played on iOS 8 #662

Closed
liuweifeng opened this issue Dec 9, 2014 · 5 comments
Closed

gif animation can not be played on iOS 8 #662

liuweifeng opened this issue Dec 9, 2014 · 5 comments

Comments

@liuweifeng
Copy link

@liuweifeng liuweifeng commented Dec 9, 2014

Sorry for my poor English.
If the gif is the first image, no problem; if you slide from the other image to th gif, the gif not be played on iOS 8

Demo is here ~

@dimsemenov
Copy link
Owner

@dimsemenov dimsemenov commented Dec 10, 2014

Thanks for bug report. Here is what I've found:

  • Issue doesn't seem to happen on iOS7.
  • GIF image seems to freeze only when it was out of the window.
  • Forcing paint on image when it's "current" fixes the issue, for example such code can be used:
var iOSv;
if (/iP(hone|od|ad)/.test(navigator.platform)) {
    iOSv = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
    iOSv = parseInt(iOSv[1], 10);
}

if(iOSv >= 8) {
    yourGalleryInstance.listen('afterChange', function() {
        if(gallery.currItem.src.indexOf('.gif') > 0) {
            var currHolder = gallery.itemHolders[1];
            if(currHolder && currHolder.el) {
                var imgs = currHolder.el.getElementsByClassName('pswp__img');
                if(imgs.length) {

                    var img = imgs[imgs.length - 1];
                    // toggle opacity on gif IMG
                    img.style.opacity = img.style.opacity == 0.99999 ? 1 : 0.99999;
                }

            }
        }
    });
}

Even though this code fixes the issue, I don't recommend to add animated gifs in PhotoSwipe at all, as it hurts performance a lot.

Also, reducing size of gif might help (even by changing only w and h properties that you pass to PhotoSwipe), see issue #820

Loading

@liuweifeng
Copy link
Author

@liuweifeng liuweifeng commented Dec 12, 2014

@dimsemenov , very good! It works! Thank you very much !

Loading

@liuweifeng liuweifeng closed this Dec 12, 2014
@andfinally
Copy link

@andfinally andfinally commented Apr 10, 2015

@dimsemenov PhotoSwipe is great, thanks! Have you considered applying visibility: hidden to the parents of non-current images? Maybe this will reduce repaints and improve performance when some of the images are animated GIFs.

Loading

@dimsemenov
Copy link
Owner

@dimsemenov dimsemenov commented Apr 10, 2015

@andfinally, PhotoSwipe keeps only 3 slides in DOM, I don't think that hiding 2 nearby slides will increase performance much, but it should be tested to tell for sure. You can hide them in afterChange event gallery.itemHolders[0], gallery.itemHolders[2] are prev and next slide DOM elements.

Loading

@andfinally
Copy link

@andfinally andfinally commented Apr 10, 2015

@dimsemenov I see, thanks!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants