I used SMIL to animate the SVG image, then used that image as the background for the DOM element (e.g. button ).
For example, this is an SVG image ( http://mattstuehler.com/spinner.svg )
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"> <g fill="none" stroke="#1e81cc" stroke-width="4"> <circle cx="50%" cy="50%" r="18" stroke-opacity="0.3"/> <path d="M20,2 A18,18 0 0,1 38,20"> <animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="1s" repeatCount="indefinite"/> </path> </g> </svg>
However, now that SMIL is deprecated, how would you do this with CSS only?
Thanks in advance!
button { width: 200px; height: 60px; background-color: #eee; background-image: url(http://mattstuehler.com/spinner.svg); background-repeat: no-repeat; background-position: center center; background-size: 50px 50px; border: none; -webkit-appearance: none; }
<button>Hello</button>
source share