Scaling up the size of SVG icons in a webpage

 I scale up the size of my SVG icons on 'hover' by setting the 'font-size' rather than using a 'scale3d' 'transform'.


I use 'ems' for the size of my SVG icons.


I keep the SVG icona centred in the same place by using a minus 'translate' 'transform'.


Here is an example:


    .catNearBriefIntron:hover

    {

        font-size: 200%;

        transform: translate(-25%, -25%);

    }


I translate by '-25%' rather than '-50%' because I only have to move the centre of the SVG.


Using 'scale3d' is quicker as it can run on the GPU. But setting the 'font-size' looks better as the SVG is completely redrawn at the new size.


Increasing the 'font-size' means the icon may take up more space and nearby elements may be reflowed. So I set a parent container's 'position' to be 'relative' and then give the icon a 'position' of 'absolute'


The scaling using 'font-size' can look a bit jerky in my game. On small pages this scaling looks fine. Maybe this is because other CSS animations are running all the time in my game.


I tried scaling up by increasing the 'width' and 'height' and adjusting the 'left' and 'top' positions. These sizes are in 'em's. I found no difference in performance.





Comments

Popular posts from this blog

How a CSS fish animation works

Adding 'inert' HTML attribute does not speed up animations

Online HTML minifiers