使用clipPathUnits="objectBoundingBox"
时,我正在处理SVG中的SVG单位计数异常
这是我能想到的最窄的版本,可以在Firefox中正常工作:
<html>
<head>
<style>
#inhibitor-image {
max-width: 100%;
max-height: 100%;
transform: translate(0, -50%);
position: absolute;
top: 50%;
}
</style>
</head>
<body>
<svg width="500" height="500" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<clipPath id="figure-crop" clipPathUnits="objectBoundingBox">
<circle cx="0.5" cy="0.5" r="0.5"></circle>
</clipPath>
</defs>
<g transform="translate(500, 500)">
<circle r="500" fill="red"></circle>
<foreignObject x="-500" y="-500" width="1000" height="1000" clip-path="url(#figure-crop)">
<img id="inhibitor-image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABAAAAAIcCAQAAADC0BTSAAAG9UlEQVR42u3WAQ0AAAgDoL9/aM3hhBQ0EwDgmQoAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAACIAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAI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AAAAAAgAACAAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAIgAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAACAAAgAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAIAAAgAACAAAAAAgAACAAAcMcC7HIcH+IVdSsAAAAASUVORK5CYII=">
</foreignObject>
</g>
</svg>
</body>
</html>
我设法弄清楚,如果我将圆的位置切换为cx="1"
和cy="1"
,那么它可以在Chrome浏览器中工作,但不能在Firefox中,这是代码段:
<html>
<head>
<style>
#inhibitor-image {
max-width: 100%;
max-height: 100%;
transform: translate(0, -50%);
position: absolute;
top: 50%;
}
</style>
</head>
<body>
<svg width="500" height="500" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<clipPath id="figure-crop" clipPathUnits="objectBoundingBox">
<circle cx="1" cy="1" r="0.5"></circle>
</clipPath>
</defs>
<g transform="translate(500, 500)">
<circle r="500" fill="red"></circle>
<foreignObject x="-500" y="-500" width="1000" height="1000" clip-path="url(#figure-crop)">
<img id="inhibitor-image" src="data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AAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAgAACAAACAAAgAAAgAACAAAIAAAAACAAAIAAAgAACAAAAAAgAACAAAIAAAgAAAAAIAAAgAACAAAIAAAAACAAAIAAAIAAAgAACAAAAAAgAACAAAcMcC7HIcH+IVdSsAAAAASUVORK5CYII=">
</foreignObject>
</g>
</svg>
</body>
</html>
我不确定发生了什么,并且我不想为不同的浏览器实现JS切换。
foreignObject和转换的组合似乎是问题所在。将变换效果直接移到元素定位时,问题似乎消失了。我的猜测是Chrome无法捕获图像CSS所应用的转换,并且计算错误的objectBoundingBox。