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

Using bgset with an svg image element #532

Closed
superbia opened this issue Sep 6, 2018 · 1 comment
Closed

Using bgset with an svg image element #532

superbia opened this issue Sep 6, 2018 · 1 comment

Comments

@superbia
Copy link

superbia commented Sep 6, 2018

First off, thanks for making and releasing Lazysizes!

I'm using the bgset plugin on an image element within an inline svg. To get this to work I've had to hack the bgset plugin from around line 127 to the following:

if (bg) {
    if(elem.nodeName === 'image'){
         elem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) );
    } else {
        elem.style.backgroundImage = 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')';
    }
}

Is it possible to get this to work without having to hack the bgset plugin?

Cheers,

Dylan

@aFarkas
Copy link
Owner

aFarkas commented Sep 10, 2018

I update the code so you can extend this part using the event bgsetproxy.

document.addEventListener('bgsetproxy', (e) => {
  e.preventDefault();
  elem.setAttribute(e.detail.useSrc);
});

@aFarkas aFarkas closed this as completed Sep 10, 2018
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

2 participants