lazyload-rails icon indicating copy to clipboard operation
lazyload-rails copied to clipboard

For some reason images are getting duplicated

Open marcelino056 opened this issue 5 years ago • 7 comments

We are getting and error after implement lazy load for images on our website, is getting the image from the source and putting it as background on style attribute, but is also displaying both images. one under the other.

screenshot-staging popchips com-2019 11 14-14_23_38

marcelino056 avatar Oct 31 '19 19:10 marcelino056

Im having the same issue. A quick work around for me was to target my img elements and apply "background-size: 100%;"

keithbooher avatar Nov 15 '19 21:11 keithbooher

I too am getting this problem. Is there anyway we can add something to config to stop this happening?

railsdevsiargao avatar Jan 22 '20 10:01 railsdevsiargao

This is happening for us too. It's only clear something is up when the background-image is not the same size. I'll apply the "background-size: 100%" to handle those (thanks @keithbooher ), but it'd be great if we could prevent duplication in the first place.

omagid-crp avatar May 08 '20 13:05 omagid-crp

That sounds pretty odd. @omagid-crp / others who still care –

  • which lazyload JavaScript library are you using?
  • could you share a brief snippet of code that reproduces the problem?

jassa avatar May 08 '20 14:05 jassa

@jassa Sure!

In the view:

<%= link_to '[link_to_relevant_website]', target: '_blank' do %>
     <%= image_tag asset_path('donate/daf-direct.png') %>
<% end %>

lazyload.js:

$('img').lazyload({ threshold: 500, effect: 'fadeIn' })

Generated HTML: Screen Shot 2020-05-08 at 10 16 14 AM

Size Discrepancy (only an issue on certain screen sizes): Screen Shot 2020-05-08 at 10 17 23 AM

Here's the version information:

/*!
 * Lazy Load - jQuery plugin for lazy loading images
 *
 * Copyright (c) 2007-2015 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   http://www.appelsiini.net/projects/lazyload
 *
 * Version:  1.9.7
 *
 */

And in our Gemfile.lock, here's the version referenced:

lazyload-rails (0.5.0)

Let me know if there's anything important I've left out.

omagid-crp avatar May 08 '20 14:05 omagid-crp

@omagid-crp You may need to set the width & height in your image_tag (or via CSS)

If that doesn't do the trick, I'd suggest reading more at https://github.com/tuupola/lazyload/blob/d3ad81c12332a0f950c6c703ff975b60350405a4/README.md#blur-up-images

Link to 1.9.7 lib docs ^

This gem helps integrate lazyload.js with Rails image_tag helpers, but the background-image property you're seeing added is coming from the JavaScript lib itself.

Good luck!

jassa avatar May 08 '20 20:05 jassa

Thanks a lot! I appreciate it!

omagid-crp avatar May 11 '20 12:05 omagid-crp