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 {
          constructor(sketch) {
            this.sketch = sketch;
        
            this.initialize();
          }
        
          initialize() {
            this.mouse = new Vector3(0, 0, 0);
            this.touchStart = new Vector3(0, 0, 0);
            this.touchMove = new Vector3(0, 0, 0);
            this.touchEnd = new Vector3(0, 0, 0);
        
            this.delta = 1;
        
            this.setupEvents();
          }
        
          setupEvents() {
            this.sketch.canvas.addEventListener('mousemove', this.onMousemove.bind(this), false);
            this.sketch.canvas.addEventListener('touchstart', this.onTouchstart.bind(this), false);
            this.sketch.canvas.addEventListener('touchmove', this.onTouchmove.bind(this), false);
            this.sketch.canvas.addEventListener('touchend', this.onTouchend.bind(this), false);
            this.sketch.canvas.addEventListener('wheel', this.onWheel.bind(this), false);
          }
        
          onMousemove(e) {
            this.mouse.x = e.clientX / window.innerWidth * 2 - 1;
            this.mouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
            this.mouse.z = 0;
          }
        
          onTouchstart(e) {
            const touch = e.targetTouches[0];
        
            this.touchStart.x = touch.pageX;
            this.touchStart.y = touch.pageY;
            this.touchStart.z = 0.0;
        
            this.mouse.x = touch.pageX / window.innerWidth * 2 - 1;
            this.mouse.y = -(touch.pageY / window.innerHeight) * 2 + 1;
            this.mouse.z = 0;
          }
        
          onTouchmove(e) {
            const touch = e.targetTouches[0];
        
            this.touchMove.x = touch.pageX;
            this.touchMove.y = touch.pageY;
            this.touchMove.z = 0.0;
        
            this.touchEnd.x = this.touchStart.x - this.touchMove.x;
            this.touchEnd.y = this.touchStart.y - this.touchMove.y;
            this.touchEnd.z = 0.0;
        
            this.mouse.x = touch.pageX / window.innerWidth * 2 - 1;
            this.mouse.y = -(touch.pageY / window.innerHeight) * 2 + 1;
            this.mouse.z = 0;
        
            if (this.touchMove.y < this.touchStart.y) {
              this.delta += (this.touchEnd.y - this.touchStart.y) * 0.0001;
            } else {
              this.delta -= (this.touchEnd.........完整代码请登录后点击上方下载按钮下载查看

网友评论0