So. In an attempt to make my site/rulebook far more interactive, I want to be able to utilise the svg images I’ve been making and animate between them with some simple Javascript and CSS.
The SVGs
Turns out the SVGs (scalable vector graphics) by default in this template were wrapped in <img> tags, this isn’t good to be able to select parts of them.
Normally I reference my images by a simple shortcode , that works great! Nice and simple to type with VS Code doing autofills and image previews for all my images. Simple file management.
Unfortunately, when wrapped in img tags, it kinda just groups all the svg together in one block that you can’t do much with. Rather than being able to utilise layers that I can easily set up in Illustrator.
This sent me down a rabbit whole of working out how to create a shortcode that would work with svgs.
After a lot of trial and error, it turned out the solution was quite simple. It now lives in the /layouts part of the site, in /shortcodes, and is an svg.html file that looks like this:
Now I can have all my svgs living in my assets folder, and can link to them like this in my Markdown blogposts like this:
1
2
{{ < svg "image-title.svg" > }}
Might add some extra functionality later if I need it, but for now it’s very simple. Might need to include lazy loading etc. (is that possible with svgs?) We’ll see!
The Javascript
I hate Javascript with a passion. But sometimes I’ve just got to use it. Here’s the code I currently have to enable 60 degree rotations (perfect for hexagons):
It wasn’t appearing quite as I’d like, so I asked the ol’ ai to assist. I’m sure I could prompt it to simplify but want to avoid. It spat out this monstrosity:
I’ll be adding like crazy now I have access to my svgs. But will likely have some hover effects that could make things very tidy. But need to design mobile first.
Lava your comments here
Loading comments...