Last active
August 29, 2015 13:57
-
-
Save anderflash/9691395 to your computer and use it in GitHub Desktop.
Usar JavaScript em SVG externo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Primeiro você usa a tag object (e não o img) --> | |
<object data="assets/svg/armor.svg" type="image/svg+xml" onload="extract($(this));" id="elema"></object> | |
<script type="text/javascript"> | |
//Depois você extrai o fonte | |
function extract(obj) { | |
myid = obj.attr('id'); | |
var svg = document.getElementById(myid); | |
var svg = svg.contentDocument; | |
var svg = svg.documentElement; | |
$('#' + myid).replaceWith(svg); | |
} | |
// E daí você pode usar as propriedades do DOM via JavaScript | |
$('.leather').css('fill','#0bffab'); //CHANGE FILL COLOR | |
$('.leather').css('stroke','#0ccccc'); //CHANGE STROKE COLOR | |
$('.leather').css('stroke-width','2'); //STROKE WIDTH | |
$('.ghost-boots').css('fill-opacity','0.6'); //AN OPACITY CONTROL FOR JUST THE FILL | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment