js实现canvas三维文字发光重影鼠标交互效果代码

代码语言:html

所属分类:动画

代码描述:js实现canvas三维文字发光重影鼠标交互效果代码

代码标签: canvas 文字 交互

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!doctype html>
<html>

<head>
   
<meta charset="utf-8">


   
<style>
        body
, html {
         
margin: 0;
         
background: -webkit-radial-gradient(center, ellipse cover, #111 10%, #333 90%);
       
}
       
        canvas
{
         
display: block;
         
cursor: crosshair;
       
}
       
        h2
{
         
position: absolute;
         
bottom: 10px;
         
width: 100%;
         
letter-spacing: 4px;
         
text-align: center;
         
font-weight: bold;
         
font-size: 1em;
         
font-family: Arial, Helvetica, sans-serif;
         
color: #AAA;
       
}
   
</style>

</head>

<body>

   
<canvas id="canvas"></canvas>

   
<h2>移动鼠标!</h2>

   
<script>
        "use strict";
       
        class Vector {
          constructor(x, y) {
            this.x = x;
            this.y = y;
          }
       
          add(v) {
            return new Vector(
              this.x + v.x,
              this.y + v.y);
          }
       
          addTo(v) {
            this.x += v.x;
            this.y += v.y;
          }
       
          sub(v) {
            return new Vector(
              this.x - v.x,
              this.y - v.y);
          }
         
          subFrom(v) {
            this.x -= v.x;
            this.y -= v.y;
          }
         
          mult(n) {
            return new Vector(this.x * n, this.y * n);
          }
         
          div(n) {
            return new Vector(this.x / n, this.y / n);
          }
         
          setAngle(angle) {
            var length = this.getLength();
            this.x = Math.cos(angle) * length;
            this.y = Math.sin(angle) * length;
          }
         
          setLength(length) {
            var angle = this.getAngle();
            this.x = Math.cos(angle) * length;
            this.y = Math.sin(angle) * length;
          }
         
          getAngle() {
            return Math.atan2(this.y, this.x);
          }
         
          getLength() {
            return Math.sqrt(this.x * this.x + this.y * this.y);
          }
       
          getLengthSq() {
            return this.x * this.x + this.y * this.y;
          }
       
          distanceTo(v) {
            return this.sub(v).getLength();
          }
        }
       
        var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
       
        function _classCallCheck(instance, Constructor) { if (!(instance.........完整代码请登录后点击上方下载按钮下载查看

网友评论0