Skip to content
Grav 2.0 is officially stable. Read the announcement →
Plugins

Lazy-load plugin

Started by matt 8 years ago · 2 replies · 1913 views
8 years ago

Using the lazy-load plugin within my site to load some images into a Page. I am using the ![](/images/...) {.img-fluid} to reference the image.

However the image does not show, only the text/title of the image.

If I remove the following block from lazy-load.php though the images do show...

PHP
$img_srset = $image->getAttribute("srcset");
                    $image->setAttribute("data-src", $img_src);
                    $image->setAttribute("data-srcset", $img_srset);
                    $image->removeAttribute("src");
                    $image->removeAttribute("srcset");

With the block in place the image src is being written as data-src and without it the src is written as src.

Obviously, I shouldn't need to alter the underlying php, so How do I stop or change the src attribute from being written as data-src..?

8 years ago

If I remember correctly, that plugin is based on Lazy-Load.js. The way it's supposed to work is when the script detects the item in viewport (or within the offset), it swaps the data-src into the src. You don't want it to be on src by default (you can have a placeholder) because those will be processed by the browser and downloaded on page load.

From the sounds of it, the script isn't firing on these elements. Did you verify that .img-fluid is the trigger class? You could try temporarily adding some console.logs to the relevant script .js so that you get some ideas on what is happening and when.

8 years ago

take a look here: /forum/themes-styling/solved-lazyloading-images-with-data-src-and-data-srcset-t943

no need for the lazyload plugin :)

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Vladimir Novak, 2 weeks ago
3 291 2 weeks ago
Plugins · by Mathieu Lecouturier, 3 weeks ago
3 277 3 weeks ago
Plugins · by Slebeig, 2 months ago
1 403 2 months ago
Plugins · by Rene, 2 months ago
2 574 2 months ago
Plugins · by Xavier, 3 months ago
2 490 3 months ago