use*_*108 6 html javascript jquery html5 canvas
我们需要绘制一个与此处显示的数字线非常相似的数字线.范围如下.
什么样的抽象可以帮助我们以简单的方式做到这一点?(html5 canvas或jquery或javascript或任何其他可以生成HTML代码的框架)
小智 7
使用Canvas元素,
$(function() {
var canvas = $('canvas')[0];
var ctx = canvas.getContext('2d');
var w = canvas.width = 700;
var h = canvas.height = 400;
with(ctx) {
fillStyle = '#000';
fillRect(0, 0, w, h);
fill();
beginPath();
lineWidth = 2;
strokeStyle = '#f00';
moveTo(w/7, h/2);
lineTo(6*w/7, h/2);
stroke();
for(var i = -10;i <= 10; i++) {
beginPath();
strokeStyle = '#0f0';
lineWidth = 2;
moveTo(w/2 + i * 20, h/2 - 20);
lineTo(w/2 + i * 20, h/2 + 20);
fillStyle = '#ff0';
fillText(i, (w/2 + i * 20 )- 5, h/2 + 35);
if(!i) {
lineWidth = 4;
strokeStyle = '#f0f';
}
fill();
stroke();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我想你可以根据你的要求添加你自己的模块:)
| 归档时间: |
|
| 查看次数: |
3936 次 |
| 最近记录: |