Is it possible to ‘animate’ the code of an SVG?

I import the code of an SVG via an “Insert HTML” element.
I insert a keyframe on time 0,00.
On time 2,00 I insert a keyframe to change an attribute in the code. For instance, I would like to change the text inside the SVG so a new text appears on second 2.
But obviously any edit applied to the code is done regardless of the time, it is applied on the whole object.

i had changes of innerHTML for svg-attributes too ... and it worked for me ...

may be you're trying something that's not possible or you just do it wrong ...

Just to confirm, you're creating an 'inner HTML' keyframe? These should be generated if you are recording and you change the inner HTML (at a different point in time).

Screen Shot 2021-02-04 at 10.17.35 AM

Yes I do that.
Here's the file.

After two seconds, I would lile to change the text from ÉTOILE to STAR.
And why not change its Y position:
text class="st1 st2" id="text92" x="142" y="269" where y becomes 250.

But it does not save the changes. (20.9 KB)

Ah -- I see what's going on. The element would need to be in a regular rectangle: (23.8 KB)

(This is a bug where it appears as though you can set frames on HTML widgets)


So instead of using “Insert HTML”, we draw a rectangle and add the code in it?
Is that the standard practice or do you plan to fix it so that with ‘Insert HTML’ it works too?

a so called widget produces an iFrame, which is an independent html-document.

I think we would disable inner HTML keyframing for HTML Widgets, since changing the src of a HTML widget would flash the content and look bad. (We can't dynamically change the innerHTML of a iframe in the same way we can do that for a rectangle)


btw: will the change of innerHTML change the whole innerHTML or just the changed parts? considering performance ...

I was thinking about that and I thought: “Maybe where we change the code, Hype will just make a copy of that line to ‘animate’ it so it doesn't need to duplicate the whole code”.

In the case of <div>-based elements, Hype does a simple element.innerHTML = newValue;.

We can't do a text diff, as browsers do not store innerHTML as text data and there's no way to transmit such a diff.

We could do a DOM diff, where we would build a structure of the new Inner HTML, compare it to the current browser DOM structure, and then only replace nodes that have changed. However, Hype's runtime would then need to fully understand how to parse HTML, and it would be gigantic in size. It would likely not result in performance improvement either in most if not all cases, since we're doing a lot of work that is done anyways with a full innerHTML replacement, and in JavaScript to boot.

React and its kin have a similar idea of diffing the "Virtual DOM." This is faster than what we could do because a) they are not parsing HTML, instead working with their own structured data from the get-go and b) they are reading from their own in-memory contents and not making DOM queries - they assume their view on the DOM is uncorrupted from what they have in their own memory. In fact, despite performance claims about React, it really isn't very fast in a lot of cases (they are doing work a browser still has to do), and most certainly is much slower than javascript code that surgically alters the correct property.

Therefore if you know what you are changing and there are performance problems in changing it through an entire innerHTML substitution, then you should use JS to change the specific part yourself.

Anyhow, to the original point, we've definitely seen confusion about HTML Widgets vs. Rectangles and have long wanted to clarify the distinction of div vs. iframe-based elements in some way.


thx for the detailed explanation @jonathan

Very technical side note (not for the OP but for nerds): You can do some stuff with Hype Handlebars

It could be done by defining any arbitrary inner HTML containing the Handlebars notation, and Handlebars actually turns it into a function generating a string. Its pretty fast. Hence, updates do render the whole branch but by executing the dynamically prepared function based on the Handlebar syntax. The Only missing thing for this is the ability to hook up arbitrary animated properties in Hype as it currently needs code to update the values and that is the moment you lose no code people. Certainly, there isn’t only one way to Rome… another could be the "modern" custom elements…

There are even more ways like using anime.js (animation library etc.). The most obvious… key frameable SVG animations would be the best, though.

If it is mandatory to put the code of an SVG into a Rectangle, then it means that a JavaScript can manage the content of that SVG, right?

Let's say that I have groups in the document.
Can I call with a JavaScript to hide/make visible a group of the SVG?

Here's an example attached. (4.5 KB)

As you can see, there are two groups: BASE and COULEURS.
The attribute to show/hide is display.

But I wonder if a JS can play with this.

The displayproperty for svg works the same as for html-elements.
Also the selectors in js do ...

To change an elements attribute the first step to do is getting it.
in your case you've set id's, so here is a on how to get an element by id:

one possibility to change its style:

Hi, thank you, I'm not a developer and from what I understand these codes listed on the sites you mentioned call for an ID. Is this the ID of each group?

bm-capture- 2021-02-05 à 09.33.05

Did it! But realized why it didn't work. A double-click on the button is necessary to make the JS work the first time. I have inverted the logic in the JS so that it inherits the hidden status. Now it works great. (18.7 KB)


another approach to achieve the same could be to toggle a css-class to remove/apply its styles:

1 Like

That's level 2, but more complicated for designers as they need to create Graphic Styles in Illustrator. With duplicated objets on layers, it's much easier to play with IDs.


un premier appel de la fonction "layers" with onLoad ou sur le timeline évite le deuxième appui sur le bouton.

a first call to the "layers" function with onLoad or on the timeline avoids the second press on the button.