-
I'm trying to lazy load the background-image of I'm using a slightly modified version of the My target div starts like this:
The callback script looks like this:
The end result is this:
...but the background image isn't rendering. What am I doing wrong? I'm guessing this has something to do with actually rendering the image? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
(facepalm) The image I was trying to load included a space. Because I hadn't enclosed the background-image:url in quotes, it was erroring. Corrected code:
|
Beta Was this translation helpful? Give feedback.
(facepalm)
The image I was trying to load included a space. Because I hadn't enclosed the background-image:url in quotes, it was erroring.
Corrected code:
<script>
//add simple support for background images:
document.addEventListener('lazybeforeunveil', function(e){
var bg = e.target.getAttribute('data-bg');
if(bg){
e.target.setAttribute("style", "background-image: url('" + bg + "')");
}
});
</script>