以下是我的代码,
var content = document.getElementById('weatherForecastCanvas');
var ctx = content.getContext("2d");
ctx.strokeStyle = "#fff";
ctx.fillStyle = "#fff";
ctx.lineWidth = 3;
//最高1
ctx.arc(xPoints[0], yPoints[0], 3, 0, Math.PI * 2, true);
////////////////////开始最高温度的线///////////////////////////////
ctx.fillText("" + a[0] + "℃", xPoints[0] - 10, yPoints[0] + 20);
ctx.moveTo(xPoints[0], yPoints[0]);
ctx.lineTo(xPoints[1], yPoints[1]);
//最高2
ctx.arc(xPoints[1], yPoints[1], 3, 0, Math.PI * 2, true);
ctx.fillText("" + a[1] + "℃", xPoints[1] - 10, yPoints[1] + 20);
ctx.moveTo(xPoints[1], yPoints[1]);
ctx.lineTo(xPoints[2], yPoints[2]);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
var canvas = document.querySelector('canvas'),
context = canvas.getContext('2d'),
w, h;
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
var x=y=0;
var maxX = 200,
maxY = 200;
var interVal ;
context.strokeStyle = "red";
context.fillStyle = "blue";
context.lineWidth = 3;
//定时画
function draw(){
if(x<maxX&&y<=maxY){
context.lineTo(x+=10, y+=10);
context.stroke();
}else{
clearInterval(interVal);
}
}
//另一种画
function drawFrame(){
interVal = window.requestAnimationFrame(drawFrame, canvas);
if(x<maxX&&y<=maxY){
context.lineTo(x+=10, y+=10);
context.stroke();
}else{
window.cancelAnimationFrame(interVal);
}
}
context.moveTo(x,y);
// interVal = setInterval(draw, 500);
drawFrame();
你好,我是AI助理
可以解答问题、推荐解决方案等
评论
全部评论 (0)