I was playing around with loading images and found SvgCircus - basically it lets you develop animated SVGs. Here's an example of one I generated.
If I simply put this svg in my index.html it works fine. However if I try to use it in a React component I can only get the static image to load - no animation. I tried this using the dangerouslySetInnerHTML parameter in a span to load the raw string, and <use xlinkHref={filename}></use>, but both of these load the static image. I am new to React but my best guess is that the javascript that comes with the svg file is not loaded.
I have a work around - put the full svg on my index.html so it loads on page load and display: none it, and then when it is time to use it show it. I was wondering if I am overlooking anything or if there is a more elegant solution.
When you include html in react components, it is not 100% html. You need to rewrite DOM attributes in camel case e.g. stroke-opacity would be strokeOpacity.
I would think this would cause the animation issue.
Related
I am creating SVGs directly in the client. Therefore, in my Javascript in the client I am creating the raw SVG and manipulating it depending on the user input.
I took the raw SVG and placed it in a file and then displayed that SVG file right next to the raw inline SVG. The result was much more crispy.
Here is the raw inline SVG:
Compare this to the SVG when placed in a file and using an tag:
As you can see the quality varies a lot!
Here is a codepen link so that you can directly grab the raw SVG if you would like to perform tests: https://codepen.io/fabiansvensson/pen/WNMJpQr
<html>
<body>
<!-- THE RAW SVG -->
<svg></svg>
</body>
</html>
Importantly, I did notice that the quality seems to be better in the codepen, which leads me to think that perhaps the problem has something to do with the styling of the page. I haven't been able to find any reason why this might be. I am considering writing the raw SVG directly to file (not ideal) or somehow making the styling of the SVG independent from the rest of the page (e.g. iFrame).
Any ideas what might be causing this and how to solve the problem?
I have searched the web but the answers showing embedding the SVG into the HTML using <object>, <img>, etc. What I want to do is open a large SVG file that contains lots of images, find the image I need, and show only that image on the page. How can I do that?
File structure is:
directory
index.html
script.js
images.svg
A few steps:
Use the Fetch API to get the image data.
Use a DOM parser to parse the XML into a document.
Find the SVG subset you want. (You didn't show us your XML, but this is likely as simple as document.querySelector().)
Create an SVG element. (This is actually a bit tricky due to the namespace. See also: JavaScript createElementNS and SVG)
Append it to the relevant element on your page.
hello damn i think you can add svg in your html code and run code but you cant font-size svg in css you can use width and height in svg to big font-size ok under
Our site runs through Netscaler and we have the Lazy-loading of images activated. I'm trying to understand it's functionality and if it can be controlled in any way. For instance if specific images can be set to not lazy-load. But I can't find anything on the specific implementation of it, just articles describing how to activate it.
If I understand it correctly it works like classic js-based lazyloading by converting imagetags by adding the class lazy and moving the src to data-original attribute. Then a javascript puts the correct src back when scrolled into view. But on what implementation is it based? Tried searching all loaded sources on lazy but can't find anything specific that seems to be connected to this behaviour.
Does anyone know how the Nestcaler lazy-loading is implemented and if there are ways to control it?
I suppose you are using Front End optimization feature, from https://docs.citrix.com/en-us/netscaler/12/optimization/front-end-optimization.html it will do the following:
JPEG optimization, CSS image inlining, Image shrink-to attributes, GIF
to PNG conversion, HTML image inlining, WebP image conversion, JPEG,
GIF, PNG to JPEG-XR image conversion
You can control the policies that have the lazyload option by using expressions on said policies. For instance, you only want to apply lazy load on images from https://www.yourwebsite.com/images/ folder. You would use a policy like this:
HTTP.REQ.URL.CONTAINS("images/")
and then create and action to only use lazy load
add feo action lazyloadaction 0 -imgLazyLoad
I have an SVG sprite file which was supplied by designers for my app. The convention they'd like me to use to render their SVG icons is to load the sprite at the top of the <body> element and then render icons like this:
<svg class="u-icon-gear-dims">
<use xlink:href="#gear"></use>
</svg>
This works when I add the SVG sprite inline, that is, plop the entire contents of the SVG sprite into my template.html file. Adding the sprite inline makes the html file ugly but, more significantly, having to manually do it raises maintainability concerns.
I'm currently referencing the individual SVGs directly to render icons, but this has performance implications as there is often a split second delay when the icon has not yet been loaded.
I found this SO topic, but there does not appear to be a viable answer.
FWIW, our app uses webpack and I'm currently trying to load the SVG sprite into a template HTML file.
How can I dynamically load an SVG sprite from a file in an HTML file?
Are you using PHP? There are methods for including SVG markup inline using backend languages.
https://sheelahb.com/blog/how-to-get-php-to-play-nicely-with-svg-files/
This is a bit of a long shot, but does anyone know of a tool that can export a png from an svg input AND retain the CSS styles applied to it. I have used canvg, but everything appears black in the output, as the styles are kept in css and not part of the svg document.
The solution is web based, and i'd like to perform the conversion client side using a javascript solution if possible.
Update:
I understand that you are using an external stylesheet for your SVG markup. So I think you need a three-step solution:
Make the stylesheet declarations that apply to the SVG markup inline. This is done best client-side. I do not have a solution in source code right now, but it should be possible to use W3C DOM Level 2 Style interface implementations to find out the selectors that apply to an element, and the declarations that have been used in the corresponding blocks (document.defaultView.getComputedStyle() alone will probably result in an SVG fragment having too many inline declarations).
Convert SVG markup with inline stylesheets to PNG. This is best done server-side (e. g., with ImageMagick), so you would need to send the SVG markup to the server.
Serve the PNG resource to the user.
Those two steps could be performed on form submission where in the onsubmit attribute you do step #1 and then call the form's submit() method.
#pluke, you've asked in the comments of the reply of #PointedEars for source code to turn external CSS styling into inline styles for your SVG. I've spent hours of searching for such a tool myself, and found none. However, I've discovered a quite specific solution that applies SVG generated with Rickshaw / D3: #thirdcreed has posted the JavaScript it at: Rickshaw CSS/Axes in JSDOM - just adapt those D3 specific selectors to your custom CSS / SVG elements as needed.