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

For some reason images are getting duplicated #24

Open
marcelino056 opened this issue Oct 31, 2019 · 7 comments
Open

For some reason images are getting duplicated #24

marcelino056 opened this issue Oct 31, 2019 · 7 comments

Comments

@marcelino056
Copy link

marcelino056 commented Oct 31, 2019

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

@keithbooher
Copy link

keithbooher commented Nov 15, 2019

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

@railsdevsiargao
Copy link

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

@omagid-crp
Copy link

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.

@jassa
Copy link
Owner

jassa commented May 8, 2020

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?

@omagid-crp
Copy link

omagid-crp commented May 8, 2020

@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.

@jassa
Copy link
Owner

jassa commented May 8, 2020

@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!

@omagid-crp
Copy link

Thanks a lot! I appreciate it!

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

No branches or pull requests

5 participants