【发布时间】:2014-09-29 00:42:12
【问题描述】:
我正在尝试使用 svgs 制作动画语音气泡,但我注意到笔划上的抗锯齿缺乏清晰度并且有明显的污迹。我已经尝试通过四舍五入来解决这个问题,但这只会让污迹变得更糟——我该怎么做才能得到 1px 粗的黑线?
HTML:
<div id="inset">
<svg id="svg" width="100%" height="100%"></svg>
</div>
CSS:
body, html {
width: 100%;
height: 100%;
border: 0;
padding: 0;
margin: 0;
}
#inset {
width: 20%;
height: 50%;
position: absolute;
bottom: 0;
left: 50%;
}
#svg {
}
Javascipt:
$(function() {
var sponsorBubble = function(el, html, cornerRad) {
this.html = html,
this.width = el.parent().width(),
this.x_center = (el.parent().width()/2),
this.height = el.parent().height(),
this.arrowWidth = (el.parent().width()/4),
this.arrowHeight = (el.parent().height()/8),
this.cornerRad = cornerRad,
this.arrowRad = this.cornerRad/3,
this.arrowControlRatio = this.arrowRad * ((this.arrowWidth/2 - (this.arrowRad*2)) / (this.arrowHeight - (this.arrowRad*2)));
var bubble = s.path(
"M" +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Q" +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", Q" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", " +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Z"
);
bubble.attr({
stroke: 'black',
fill: 'none'
});
bubble.animate({
d:
"M" +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Q" +
Math.round(this.x_center - this.arrowRad + this.arrowControlRatio)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", L" +
Math.round(this.x_center - (this.arrowWidth/2) + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowHeight + this.arrowRad)
+ ", Q" +
Math.round(this.x_center - (this.arrowWidth/2) + this.arrowRad - this.arrowControlRatio)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.x_center - (this.arrowWidth/2))
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", L" +
Math.round(this.cornerRad)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", Q" +
0
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
0
+ ", " +
Math.round(this.height - this.arrowHeight - this.cornerRad)
+ ", L" +
0
+ ", " +
Math.round(this.cornerRad)
+ ", Q" +
0
+ ", " +
0
+ ", " +
Math.round(this.cornerRad)
+ ", " +
0
+ ", L" +
Math.round(this.width - this.cornerRad)
+ ", " +
0
+ ", Q" +
Math.round(this.width)
+ ", " +
0
+ ", " +
Math.round(this.width)
+ ", " +
Math.round(this.cornerRad)
+ ", L" +
Math.round(this.width)
+ ", " +
Math.round(this.height - this.arrowHeight - this.cornerRad)
+ ", Q" +
Math.round(this.width)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.width - this.cornerRad)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", L" +
Math.round(this.x_center + (this.arrowWidth/2))
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", Q" +
Math.round(this.x_center + (this.arrowWidth/2) - this.arrowRad + this.arrowControlRatio)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.x_center + (this.arrowWidth/2) - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowHeight + this.arrowRad)
+ ", L" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center + this.arrowRad - this.arrowControlRatio)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Z"
},
100
);
};
s = Snap('#svg');
var bubble_obj = new sponsorBubble($('#svg'), "test_content", 15);
});
jdfiddle: http://jsfiddle.net/L5k48hwm/
【问题讨论】:
标签: javascript jquery svg snap.svg