内容简介:翻译自:https://stackoverflow.com/questions/34332615/getting-rid-of-aliasing-on-a-svg-circular-element
我正在制作动画SVG饼图.基本上我有两个SVG元素,第一个获得50%的边界半径,第二个是我填充到特定值的圆.最后,这使得一个圆圈位于另一个圆圈之上,它们都具有相同的尺寸.
有一种似乎很难摆脱的SVG别名.它在圆圈的顶部,左侧,底部和右侧“角落”非常明显,至少在Google Chrome上是如此.
这是 HTML 部分
<figure id="pie" data-percentage="60">
<div class="receiver"></div>
<svg width="200" height="200" class="chart" shape-rendering="geometricPrecision">
<circle r="50" cx="100" cy="100" class="pie" shape-rendering="geometricPrecision"/>
</svg>
</figure>
这是我的 codepen ,可以更准确地描述问题.我尝试了各种解决方案,包括形状渲染SVG属性但无济于事.
这是一个截图,别名不像在codepen中那样可见(至少对我来说)
全svg百分比圈
我之前也遇到过这个问题: Pixel edge on circle
当您使用border-radius修改元素时会发生这种情况.
您可以在上面的链接答案中找到答案,
但我觉得如果你只使用/修改svg,它的性能和美学效果都会更好.
例:
var circ = document.getElementsByClassName("pie2");
var text = document.getElementsByClassName("text");
text = text[0];
circ = circ[0];
var maxvalue = 320;
var value = maxvalue;
var stop = false;
function increase() {
if (value > 0) {
circ.style.strokeDashoffset = value--;
text.textContent = Math.abs(Math.floor((value / maxvalue) * 100) - 100) + "%";
} else {
clearInterval(intervalid);
}
}
var intervalid = setInterval(increase, 25);
.pie {
fill: none;
stroke: #222;
stroke-width: 99;
}
.pie2 {
fill: none;
stroke: orange;
stroke-width: 100;
stroke-dasharray: 320;
stroke-dashoffset: 320;
}
.text {
font-family: Arial;
font-weight: bold;
font-size: 2em;
}
<figure id="pie" data-percentage="90">
<svg width="200" height="200" class="chart" shape-rendering="geometricPrecision">
<circle r="50" cx="100" cy="100" class="pie" shape-rendering="geometricPrecision" />
<circle r="50" cx="100" cy="100" class="pie2" />
<text class="text" x="80" y="110">0%</text>
</svg>
</figure>
翻译自:https://stackoverflow.com/questions/34332615/getting-rid-of-aliasing-on-a-svg-circular-element
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 如何摆脱 “技术思维” 的惯性?
- matlab – 摆脱图中的“图1”
- 摆脱redux繁琐操作,搭建mobx框架
- Git命令别名设置
- mybatis的typeAliases别名
- Azure中继摆脱了WCF的桎梏,走向跨平台
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Definitive Guide to MongoDB
Peter Membrey、Wouter Thielen / Apress / 2010-08-26 / USD 44.99
MongoDB, a cross-platform NoSQL database, is the fastest-growing new database in the world. MongoDB provides a rich document orientated structure with dynamic queries that you’ll recognize from RDMBS ......一起来看看 《The Definitive Guide to MongoDB》 这本书的介绍吧!