Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在vanilla javascript中创建移动行?_Javascript_Html_Animation - Fatal编程技术网

如何在vanilla javascript中创建移动行?

如何在vanilla javascript中创建移动行?,javascript,html,animation,Javascript,Html,Animation,我正在尝试用香草javascript创建一个雨的效果。下面是我尝试过的代码 我在每个间隔更新y坐标,但需要清除前一行,使其看起来像下降线效果 多谢各位 var canvas=document.getElementByIdDemoCanvas; var ctx=canvas.getContext2d; 下课{ 建造师{ 这个.x=canvas.width/2; 这个。y=0; 这个.yspeed=10; } 堕落{ this.y=this.y+this.y速度; } 展示{ 移动到这个.x,这个

我正在尝试用香草javascript创建一个雨的效果。下面是我尝试过的代码

我在每个间隔更新y坐标,但需要清除前一行,使其看起来像下降线效果

多谢各位

var canvas=document.getElementByIdDemoCanvas; var ctx=canvas.getContext2d; 下课{ 建造师{ 这个.x=canvas.width/2; 这个。y=0; 这个.yspeed=10; } 堕落{ this.y=this.y+this.y速度; } 展示{ 移动到这个.x,这个.y; ctx.lineTothis.x,this.y+10; ctx.stroke; } } 如果canvas.getContext{ 设d=新滴; setInterval=>{ d、 展示; d、 堕落; }, 500; } 只需调用ctx.clearRect0,0,ctx.canvas.width,ctx.canvas.height;,另外,在调用stroke时,您需要首先调用ctx.beginPath,所有这些:

var canvas=document.getElementByIdDemoCanvas; var ctx=canvas.getContext2d; 下课{ 建造师{ 这个.x=canvas.width/2; 这个。y=0; 这个.yspeed=10; } 堕落{ this.y=this.y+this.y速度; } 展示{ ctx.clearRect0,0,ctx.canvas.width,ctx.canvas.height ctx.beginPath 移动到这个.x,这个.y; ctx.lineTothis.x,this.y+10; ctx.stroke; } } 如果canvas.getContext{ 设d=新滴; setInterval=>{ d、 展示; d、 堕落; },500; } 只需调用ctx.clearRect0,0,ctx.canvas.width,ctx.canvas.height;,另外,在调用stroke时,您需要首先调用ctx.beginPath,所有这些:

var canvas=document.getElementByIdDemoCanvas; var ctx=canvas.getContext2d; 下课{ 建造师{ 这个.x=canvas.width/2; 这个。y=0; 这个.yspeed=10; } 堕落{ this.y=this.y+this.y速度; } 展示{ ctx.clearRect0,0,ctx.canvas.width,ctx.canvas.height ctx.beginPath 移动到这个.x,这个.y; ctx.lineTothis.x,this.y+10; ctx.stroke; } } 如果canvas.getContext{ 设d=新滴; setInterval=>{ d、 展示; d、 堕落; },500; }