特效描述:利用HTML5实现 英文字母 ABCD 动画特效。利用HTML5实现英文字母ABCD动画特效
代码结构
1. HTML代码
function foreach(array, callback) {
for(let ind=0; ind
callback(array[ind],ind);
}
}
function rand(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
class Dot {
constructor(canvas,position) {
this.canvas = canvas;
this.context = this.canvas.getContext('2d');
this.color = '#fff';
this.position = {x:position.x,y:position.y};
this.originalPosition = {x:position.x,y:position.y};
this.reachPosition = {x:position.x, y:position.y};
this.randomValue = rand(5,10);
this.glitch = false;
this.size = 1;
this.mouse = {x:0,y:0};
this.counter = 0;
}
update() {
this.glitch = rand(0,200) < this.randomValue;
let easing = this.randomValue / 50;
this.position.x += ( this.reachPosition.x - this.position.x ) * easing;
this.position.y += ( this.reachPosition.y - this.position.y ) * easing;