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

Examples with images that will not load in Codepen #1534

Closed
wants to merge 3 commits into from

Conversation

spectranaut
Copy link
Contributor

@spectranaut spectranaut commented Sep 25, 2020

Unfortunately, in codepen we cannot use the <use xlink:href.... because of cross origin policies, so the button example will not be able to load the mute/sound icon. I replaced the <use... pattern with an inline SVG. Is this the approach we want? Is there a cleaner, better looking way to inline or reference these SVGs? The previous method was cool and I'm sad to take it out.

Here is the raw githack button example

The SVGs in the menubar editor aren't rendering for a different reason -- it's because the relative paths from the CSS file do not work in codepen because all of the resources are loaded without a file structure. I'm leaving this PR in Draft in case anyone wants to chime in with a way to solve that problem other then adding A LOT of inline SVGs in the menubar editor.

Here is the raw githack for the menubar editor

@spectranaut spectranaut changed the title Codepen examples with SVG images not loading Examples with SVG images that will not load in Codepen Sep 25, 2020
@spectranaut spectranaut changed the title Examples with SVG images that will not load in Codepen Examples with images that will not load in Codepen Nov 20, 2020
@carmacleod
Copy link
Contributor

@spectranaut
I believe svg use href with a fragment id will work (I haven't done much svg, so not 100% sure, but I think it's worth a try 😄 ):

... first, define the svg in the document (create a group to contain the drawing code, and give the group an id):
<svg ...>
    <defs>
        <g id="checkmark">
            ... SVG content for drawing checkmark goes here ...
        </g>
    </defs>
</svg>

... then I think you can reuse the g content by pointing to its fragment id later in document
    (at least it would only take 3 lines, because you wouldn't need to repeat all the drawing code):
<svg viewBox=... ...>
   <use xlink:href="#checkmark" />
</svg>

... then you can reuse it again and again (I think):
<svg viewBox=... ...>
   <use xlink:href="#checkmark" />
</svg>

Notes:

@spectranaut
Copy link
Contributor Author

Wow @carmacleod I was also just looking into the same idea yesterday! Good to know there is a +1, I'll try it on some examples today.

@spectranaut
Copy link
Contributor Author

closing in favor of #1642

@spectranaut spectranaut closed this Dec 2, 2020
@zcorpan zcorpan deleted the codepen-images branch October 29, 2021 19:57
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

Successfully merging this pull request may close these issues.

2 participants