As soon as I saw the new YouTube Player and its new morphing play/pause button, I wanted to understand how it was made and replicate it myself.
From my analysis it looks like YouTube is using [SMIL animations][1]. I could not get those animations to work on browsers other than Chrome and it appears [that they are deprecated and will be removed][2]. I settled for the following technique:
-
Define the icon
path
elements inside adefs
element so that they are not drawn. -
Draw one icon by defining a
use
element whosexlink:href
attribute points to one of thepath
s defined in the previous step. Simply [changing this attribute to point to the other icon is enough to swap them out][3], but this switch is not animated. To do that, -
Replace the
use
with the actualpath
when the page is loaded.