mercredi 25 janvier 2017

Changing color on all svg

i'm trying to use an effect i found on Codepen, changing colours on SVG. There's an issue on the script that makes the effect affect only the first SVG and not the others on the page as i would like.

Any help? thanks

var select = function(s) {
    return document.querySelector(s);
};
var svgItem = select('svg');
var chars = '0123456789ABCDEF'.split('');

var randomColor = function () {
  var color = '#';
  for (var i = 0; i < 6; i++)
    color += chars[Math.floor(Math.random() * 16)];
  return color;
};

setInterval(function () {
  svgItem.style.fill = randomColor();
}, 1500);
svg {
   fill: #000000;   
   transition: fill 1.5s ease;
   -webkit-transition: fill 1.5s ease;
}
<script src="http://ift.tt/1oMJErh"></script>
<svg height="100" width="100">
<circle cx="40" cy="40" r="40"></circle>
</svg>


<svg height="100" width="100">
<circle cx="40" cy="40" r="40"></circle>
</svg>



Aucun commentaire:

Enregistrer un commentaire