Skip to content

Instantly share code, notes, and snippets.

@enjalot
Forked from erikhazzard/gist:1821595
Created February 13, 2012 23:58
Show Gist options
  • Save enjalot/1821600 to your computer and use it in GitHub Desktop.
Save enjalot/1821600 to your computer and use it in GitHub Desktop.
getbbox cs getcomputedlength
<html>
<meta charset='utf-8' />
<head>
</head>
<body>
<svg>
<text id="text_node" y="1em">
<tspan>You</tspan>
<tspan dx='.25em'>shall</tspan>
<tspan dx='.25em'>not</tspan>
<tspan dx='.25em'>pass</tspan>
<tspan x=0 dy='.9em'>Fly</tspan>
<tspan dx='.25em'>you</tspan>
<tspan dx='.25em'>fools</tspan>
</text>
</svg>
<script>
var node = document.getElementById('text_node')
var bbox = node.getBBox();
var computed_text_length = node.getComputedTextLength();
console.log('BBOX width: ', bbox.width);
console.log('Computed text length: ', computed_text_length);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment