【发布时间】:2012-03-21 19:12:44
【问题描述】:
例如,这是我的 svg 代码。
<rect x="1531.718" y="1688.217" opacity="0.8" fill="#FEE880" enable-background="new " width="40.67" height="27"></rect>
<rect x="1531.718" y="1661.217" opacity="0.8" fill="#F67B9E" enable-background="new" width="40.67" height="27"></rect>
<rect x="1335.718" y="1053.356" opacity="0.8" fill="#FEE880" enable-background="new" width="236.67" height="153.01"></rect>
<polygon opacity="0.8" fill="#F67B9E" enable-background="new " points="1572.388,970.547 1572.388,1016.547
1509.718,1016.547 "></polygon>
当 div 环绕 svg 中的多边形时,如何获取位置、宽度和高度。我更喜欢使用 jQuery。
我为 svg 中的“rect”做了这个,它就像魅力一样!:) 这是代码:
$('#mapArea').load('src/124/124.svg', function(){
var inputs = $('#mapArea').find('rect');
var inputsCount = inputs.size();
for (i=1;i<inputsCount;i++){
var positionX = $('#mapArea').find('rect:eq('+i+')').attr('x');
var positionY = $('#mapArea').find('rect:eq('+i+')').attr('y');
var width = $('#mapArea').find('rect:eq('+i+')').attr('width');
var height = $('#mapArea').find('rect:eq('+i+')').attr('height');
$('#mapArea').after('<div style="position:absolute;width:'+width+'px;height:'+height+'px;background:rgba(0,0,0,0.4);top:'+positionY+'px;left:'+positionX+'px;">');
}
我不能像矩形那样做,因为多边形只有一个属性...点!
【问题讨论】: