js实现文字变换排列动画效果代码
代码语言:html
所属分类:动画
代码描述:js实现文字变换排列动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
* {
padding: 0;
margin: 0;
user-select: none;
}
</style>
</head>
<body>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script>
<script>
const getRandomNumber = function (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
/**
* Time class
*/
class Time {
constructor(sketch) {
this.sketch = sketch;
this.initialize();
}
initialize() {
const time = Date.now();
//this.setupCanvas();
this.startTime = time;
this.lastTime = time;
}
setupCanvas() {
document.
getElementsByTagName("body")[0].
appendChild(document.createElement("canvas"));
this.canvas = document.getElementsByTagName('canvas')[1];
this.ctx = this.canvas.getContext('2d');
this.ctx.font = '16px sans-serif';
const metrics = this.ctx.measureText('000 FPS');
this.width = this.canvas.width = metrics.width;
this.height = this.canvas.height = 16;
this.canvas.style.position = 'fixed';
this.canvas.style.zIndex = '9999';
this.canvas.style.background = 'black';
this.canvas.style.display = 'block';
this.canvas.style.bottom = '0';
this.canvas.style.right = '0';
}
calculateTime() {
const time = Date.now();
this.elapsedTime = time - this.startTime;
this.fps = 1000 / (time - this.lastTime);
this.lastTime = time;
}
drawFPS() {
const ctx = this.ctx;
ctx.clearRect(0, 0, this.width, this.height);
ctx.save();
ctx.fillStyle = 'rgb(2, 230, 231)';
ctx.font = '16px sans-serif';
ctx.textAlign = 'right';
ctx.textBaseline = 'bottom';
ctx.fillText(this.fps.toFixed() + ' FPS', this.width, this.height);
ctx.restore();
}
getElapsedTime() {
return this.elapsedTime;
}}
/**
* Dat class
*/
class Dat {
constructor(sketch) {
this.sketch = sketch;
this.initialize();
}
initialize() {
this.gui = new dat.GUI();
this.parameters = this.setParameters();
this.controller = this.setController();
this.gui.close();
}
setParameters() {
let parameters;
parameters = {
number: 20,
radius: 10,
scale: 0.1,
length: 25,
font: 'serif' };
return parameters;
}
setController() {
let controller;
controller = {
number: this.gui.add(this.parameters, 'number', 3, 50, 1).
onChange(() => this.sketch.initialize()),
radius: this.gui.add(this.parameters, 'radius', 1, 36, 1).
onChange(() => this.sketch.initialize()),
scale: this.gui.add(this.parameters, 'scale', 0.01, 0.5, 0.01).
onChange(() => this.sketch.initialize()),
length: this.gui.add(this.parameters, 'length', 10, 50, 1).
onChange(() => this.sketch.initialize()),
font: this.gui.add(this.parameters, 'font').
onChange(() => this.sketch.initialize()) };
return controller;
}}
/**
* vector3 class
* If you want to function please add function.
*/
class Vector3 {
constructor(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}}
/**
* Mouse class
*/
class Mouse {
cons.........完整代码请登录后点击上方下载按钮下载查看
网友评论0