6
<body style="width:1000px;height:1000px;">
<div id="d" style="display:inline-block;">
<svg id="s" xmlns="http://www.w3.org/2000/svg" version="1.1" width="200px" height="200px">
<rect width="200px" height="200px" style="fill:rgb(0,0,255);"/>
</svg>
</div>
</body>
var div = document.getElementById('d');
var rect = div.getBoundingClientRect();
alert(rect.width); //200
alert(rect.height); //205 (in safari), 204.5 in other browsers
var svg = document.getElementById('s');
var rect = svg.getBBox();
alert(rect.width); //200
alert(rect.height); //200
Próbuję uzyskać szerokość i wysokość div elementu nadrzędnego. Z jakiegokolwiek powodu getBoudingClientRect podaje mi nieprawidłową wartość wysokości (205 lub 204,5). Szerokość jest prawidłowa, ale wysokość jest wyłączona. Jakieś pomysły?getBoundingClientRect, niepoprawna wartość wysokości dla wbudowanego SVG
Wysokość jest poprawna, ma 204,5 piksela wysokości. – Stijn
powinno być 200px – user2800679
możliwy duplikat [Istnieje 4px luka poniżej elementów canvas/wideo/audio w HTML5] (http://stackoverflow.com/questions/8600393/there-is-a-4px-gap-below- canvas-video-audio-elements-in-html5) – Stijn