【发布时间】:2015-08-06 05:21:53
【问题描述】:
这是我尝试使用画布实现的设计:
我必须在圆的半径上获得渐变,并在边缘带有一些内部阴影。
我对画布的了解非常少,因此非常感谢任何帮助。
我正在使用jquery旋钮插件显示进度条:JQUERY-KNOB
HTML
<div class="demo">
<div style="width: 100%; margin-bottom: 20px; margin-left:100px;">
<br>
<br>
<input class="knob" data-width="100%" value="45">
</div>
</div>
JS
$(function ($) {
$(".knob").knob({
class: 'group-canvas',
change: function (value) {
//console.log("change : " + value);
},
release: function (value) {
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
cancel: function () {
console.log("cancel : ", this);
},
/*format : function (value) {
return value + '%';
},*/
draw: function () {
// "tron" case
if (this.$.data('skin') == 'tron') {
this.cursorExt = 0.3;
var a = this.arc(this.cv) // Arc
,
pa // Previous arc
,
r = 1;
this.g.lineWidth = this.lineWidth;
if (this.o.displayPrevious) {
pa = this.arc(this.v);
this.g.beginPath();
this.g.strokeStyle = this.pColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, pa.s, pa.e, pa.d);
this.g.stroke();
}
this.g.beginPath();
this.g.strokeStyle = r ? this.o.fgColor : this.fgColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, a.s, a.e, a.d);
this.g.stroke();
this.g.lineWidth = 2;
this.g.beginPath();
this.g.strokeStyle = this.o.fgColor;
this.g.arc(this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
this.g.stroke();
return false;
}
}
});
// Example of infinite knob, iPod click wheel
var v, up = 0,
down = 0,
i = 0,
$idir = $("div.idir"),
$ival = $("div.ival"),
incr = function () {
i++;
$idir.show().html("+").fadeOut();
$ival.html(i);
},
decr = function () {
i--;
$idir.show().html("-").fadeOut();
$ival.html(i);
};
});
CSS
.group-canvas {
width: 20vh !important;
height: 20vh !important;
}
.knob {
margin-top: 14vh !important;
width: 24vh !important;
height: 13vh !important;
font-size: 9vh !important;
margin-left: -32vh !important;
}
这就是我到目前为止通过上面的代码和更改http://anthonyterrien.com/js/jquery.knob.js 文件中的 fgColor 实现的目标(我知道我不应该编辑这个文件,但作为一个试验,我已经更改了 fgColor) :
fgColor: this.$.data('fgcolor') || '#dd3002',
【问题讨论】:
-
我为您发布了一个很好的起点。这里是深夜,所以有点粗糙——但这是一个好的开始。晚安!
-
谢谢你,非常感谢。我去看看。
标签: javascript jquery html css canvas