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

Safari images with srcset not showing #732

Closed
fabianjaehnke opened this issue Oct 20, 2017 · 8 comments
Closed

Safari images with srcset not showing #732

fabianjaehnke opened this issue Oct 20, 2017 · 8 comments

Comments

@fabianjaehnke
Copy link

http://www.besau-marguerre.de/
on this wordpress site the images do not show up if they have a srcset set.

@desandro
Copy link
Member

Thanks for reporting this issue. This is actually two separate issues that we're both tracking.

I'm closing this issue here. Please follow those issues.

@tomusborne
Copy link

tomusborne commented Nov 22, 2017

Are those issues related? I couldn't find much information regarding this exact issue.

This is happening to me without masonry or imagesLoaded - only Infinite Scroll.

It seems images with srcset simply aren't displayed in Safari if they're loaded via Infinite Scroll.

@lsloss
Copy link

lsloss commented Nov 22, 2017

Same here. Not using imagesLoaded or Masonry. The height of appended images is being set to 0 if img height is set to auto in the CSS. Disabling the Wordpress srcset feature or removing height auto fixes this but both are far from ideal.

@nicolas-owp
Copy link

Hello @fabianjaehnke, @tomusborne, @lsloss, I found a solution for this issue. I just take the width and height attributes of the items and add them in JS, like this:

$container.on( 'load.infiniteScroll', function( event, response, path, items ) {

	var $items = $j( response ).find( '.item-entry' );

	$items.imagesLoaded( function() {

		// Take image width & height attrs to fix Safari issue
		var $image = $items.find( 'img' );
		$image.css( {
			width 	: $image.attr( 'width' ),
			height 	: $image.attr( 'height' )
		} );

	} );

} );

It is not a perfect solution but that fix the Safari issue :)

@nboliver
Copy link

nboliver commented Jan 5, 2018

Another option that seems to work for me is to force the images to be parsed again after they are loaded:

this.infiniteScrollInstance.on('append', (response, path, items) => {
  $(items).find('img').each((index, img) => {
    img.outerHTML = img.outerHTML;
  });
});```

@nicolas-owp
Copy link

Hello @nboliver, even better :)
Work perfectly for me too, thank you very much for this tip :)

@meszarosrob
Copy link

Weird issue… not sure why it is happening, but I had to deal with it today.

@nboliver good "fix" 👍

@downFast
Copy link

downFast commented Feb 22, 2018

I just had the same issue and the above suggestions didn't work for me, what I did is calculate the image and height before they load and set height and width with js:

        $container.on( 'append.infiniteScroll', function( event, response, path ) {
          $(".article").addClass("slideIn");
          $("img").each(function() {
            var mySizes = $(this);
            getImageSize(mySizes, function(width, height){
              $(mySizes).width(width).height(height);
            });
          });
          function getImageSize(img, callback) {
            var $img = $(img);
            var wait = setInterval(function() {
              var w = $img[0].naturalWidth,
                  h = $img[0].naturalHeight;
              if (w && h) {
                  clearInterval(wait);
                  callback.apply(this, [w, h]);
                }
            }, 30);
          }
        });

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

No branches or pull requests

8 participants