为什么页面上的 SVG 图像会导致 Chrome 使用 100% 的 CPU?
我在页面上使用 SVG 图像(通过 CSS 背景图像属性),当我在 Chrome(Windows 上的版本 11.0.696.71)中查看此页面时,我的一个 CPU 核心达到 100% 并永久保持该状态。我的 SVG 图像非常简单,在它自己的 XML 文件中定义:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:rgb(0,0,0);fill-opacity:.05"/>
</svg>
更新:
您可能需要在页面上以特定方式使用 SVG 才能遇到该问题。此 HTML 文件存在问题(目前在线位于 http://jsbin.com/amaqo4/6):
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<tr style="background: url(YOUR-SVG-FILE.svg)"><td>test</td></tr>
</table>
<div style="background: url(YOUR-SVG-FILE.svg)">test</div>
</body>
</html>
当我删除表格或 div 时,问题就消失了。
I am using an SVG image on a page (via the CSS background-image property) and when I view this page in Chrome (version 11.0.696.71 on Windows), one of my CPU cores goes to 100% and stays there permanently. My SVG image is quite simple and is defined in its own XML file:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:rgb(0,0,0);fill-opacity:.05"/>
</svg>
Update:
You may need to use the SVG in a specific way on the page to experience the problem. This HTML file has the issue (currently online at http://jsbin.com/amaqo4/6):
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<tr style="background: url(YOUR-SVG-FILE.svg)"><td>test</td></tr>
</table>
<div style="background: url(YOUR-SVG-FILE.svg)">test</div>
</body>
</html>
When I remove either the table or the div, the problem goes away.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是由 svg 元素上隐式宽度和高度 100% 引起的。在 svg 元素上显式指定
width="100%" height="100%"
会导致相同的问题。我发现可以通过使用无单位尺寸来解决该问题,例如width="1" height="1"
。这是我的 SVG 文件的修改版本,可以解决该问题:
This is caused by the implicit width and height of 100% on the svg element. Explicitly specifying
width="100%" height="100%"
on the svg element causes the same issue. I've discovered that the problem can be solved by using unit-less dimensions, e.g.width="1" height="1"
.Here is a modified version of my SVG file that fixes the problem:
可能有很多原因:
There may be many reasons: