内容简介:翻译自: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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数据密集型应用系统设计
Martin Kleppmann / 赵军平、李三平、吕云松、耿煜 / 中国电力出版社 / 2018-9-1 / 128
全书分为三大部分: 第一部分,主要讨论有关增强数据密集型应用系统所需的若干基本原则。首先开篇第1章即瞄准目标:可靠性、可扩展性与可维护性,如何认识这些问题以及如何达成目标。第2章我们比较了多种不同的数据模型和查询语言,讨论各自的适用场景。接下来第3章主要针对存储引擎,即数据库是如何安排磁盘结构从而提高检索效率。第4章转向数据编码(序列化)方面,包括常见模式的演化历程。 第二部分,我们将......一起来看看 《数据密集型应用系统设计》 这本书的介绍吧!