three实现星星粒子跟随鼠标动画效果代码

代码语言:html

所属分类:粒子

代码描述:three实现星星粒子跟随鼠标动画效果代码

代码标签: three 星星 粒子 跟随 鼠标 动画

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

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
<style>
    html,body {
	height:100%;
}
body {
	margin:0;
	background-color:#000;
}
#canvas {
	display:block;
	width:100%;
	height:100%;
}
body.o-start #canvas {
	cursor:none;
}
#message {
	position:absolute;
	right:0;
	bottom:0;
	left:0;
	color:rgba(255,255,255,0.7);
	font-family:Georgia,serif;
	font-size:0.9rem;
	text-align:center;
	letter-spacing:0.1em;
	pointer-events:none;
	opacity:0;
	transition:opacity 500ms;
}
body.o-start #message {
	opacity:1;
}
</style>
</head>

<body><canvas id="canvas"></canvas>
    <p id="message">Move your mouse</p>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.103.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script>
    <script type="module">
        
     parcelRequire = (function (init) {
  // Save the require from previous bundle to this closure if any
  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
  var nodeRequire = typeof require === 'function' && require;
  var modules = {};

  function localRequire(name, jumped) {
    if (name in modules) {
      return modules[name];
    }

    // if we cannot find the module within our internal map or
    // cache jump to the current global require ie. the last bundle
    // that was added to the page.
    var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
    if (!jumped && currentRequire) {
      return currentRequire(name, true);
    }

    // If there are other bundles on this page the require from the
    // previous one is saved to 'previousRequire'. Repeat this as
    // many times as there are bundles until the module is found or
    // we exhaust the require chain.
    if (previousRequire) {
      return previousRequire(name, true);
    }

    // Try the node require function if it exists.
    if (nodeRequire && typeof name === 'string') {
      return nodeRequire(name);
    }

    var err = new Error('Cannot find module \'' + name + '\'');
    err.code = 'MODULE_NOT_FOUND';
    throw err;
  }

  localRequire.register = function register(id, exports) {
    modules[id] = exports;
  };

  modules = init(localRequire);
  localRequire.modules = modules;
  return localRequire;
})(function (require) {
function $parcel$interopDefault(a) {
  return a && a.__esModule ? {
    d: a.default
  } : {
    d: a
  };
}

function $pTw7$var$_toConsumableArray(arr) {
  return $pTw7$var$_arrayWithoutHoles(arr) || $pTw7$var$_iterableToArray(arr) || $pTw7$var$_nonIterableSpread();
}

function $pTw7$var$_nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance");
}

function $pTw7$var$_iterableToArray(iter) {
  if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function $pTw7$var$_arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) {
    for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
      arr2[i] = arr[i];
    }

    return arr2;
  }
}

function $pTw7$var$_classCallCheck(instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
}

function $pTw7$var$_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);
  }
}

function $pTw7$var$_createClass(Constructor, protoProps, staticProps) {
  if (protoProps) $pTw7$var$_defineProperties(Constructor.prototype, protoProps);
  if (staticProps) $pTw7$var$_defineProperties(Constructor, staticProps);
  return Constructor;
} // import * as THREE from 'three'
// import TrackballControls from 'three-trackballcontrols'
// import './three/postprocessing'
// THREE.TrackballControls = TrackballControls

/*!
 * Three.js Wrapper
 * forked from https://github.com/zadvorsky/three.bas/blob/86931253240abadf68b7c62edb934b994693ed4a/examples/_js/root.js
 */


var $pTw7$export$default =
/*#__PURE__*/
function () {
  function THREERoot(params) {
    var _this$camera$position,
        _this = this;

    $pTw7$var$_classCallCheck(this, THREERoot); // defaults

    var _params$container = params.container,
        container = _params$container === void 0 ? document.body : _params$container,
        _params$fov = params.fov,
        fov = _params$fov === void 0 ? 45 : _params$fov,
        zNear = params.zNear,
        zFar = params.zFar,
        _params$cameraPositio = params.cameraPosition,
        cameraPosition = _params$cameraPositio === void 0 ? [0, 0, 30] : _params$cameraPositio,
        _params$createCameraC = params.createCameraControls,
        createCameraControls = _params$createCameraC === void 0 ? false : _params$createCameraC,
        _params$isAutoStart = params.isAutoStart,
        isAutoStart = _params$isAutoStart === void 0 ? true : _params$isAutoStart,
        _params$pixelRatio = params.pixelRatio,
        pixelRatio = _params$pixelRatio === void 0 ? window.devicePixelRatio : _params$pixelRatio,
        _params$antialias = params.antialias,
        antialias = _params$antialias === void 0 ? window.devicePixelRatio === 1 : _params$antialias,
        _params$alpha = params.alpha,
        alpha = _params$alpha === void 0 ? false : _params$alpha,
        _params$clearColor = params.clearColor,
        clearColor = _params$clearColor === void 0 ? 0x000000 : _params$clearColor,
        aspect = params.aspect,
        _params$canvas = params.canvas,
        canvas = _params$canvas === void 0 ? document.createElement('canvas') : _params$canvas,
        _params$speed = params.speed,
        speed = _params$speed === void 0 ? 60 / 1000 : _params$speed,
        interval = params.interval,
        _params$firstTime = params.firstTime,
        firstTime = _params$firstTime === void 0 ? 0 : _params$firstTime,
        _params$isDev = params.isDev,
        isDev = _params$isDev === void 0 ? false : _params$isDev;
    this.speed = speed;
    this.interval = interval;
    this.time = this.firstTime = firstTime;
    this.stopTime = 0; // maps and arrays

    this.updateCallbacks = [];
    this.resizeCallbacks = [];
    this.objects = {}; // renderer

    this.renderer = new THREE.WebGLRenderer({
      antialias: antialias,
      alpha: alpha,
      canvas: canvas
    });
    this.renderer.setPixelRatio(pixelRatio);
    this.renderer.setClearColor(clearColor, alpha ? 0 : 1);
    this.canvas = this.renderer.domElement; // container

    this.container = typeof container === 'string' ? document.querySelector(container) : container;
    !params.canvas && this.container.appendChild(this.canvas);
    this.aspect = aspect || this.container.clientWidth / this.container.clientHeight;
    this.setSize(); // camera

    this.camera = new THREE.PerspectiveCamera(fov, this.width / this.height, zNear, zFar);

    (_this$camera$position = this.camera.position).set.apply(_this$camera$position, $pTw7$var$_toConsumableArray(cameraPosition));

    this.camera.updateProjectionMatrix(); // scene

    this.scene = new THREE.Scene(); // resize handling

    this.resize();
    window.addEventListener('resize', function () {
      _this.resize();
    }); // tick / update / render

    isAutoStart && this.start(); // optional camera controls

    createCameraControls && this.createOrbitControls(); // pointer

    this.raycaster = new THREE.Raycaster();
    this.pointer = new THREE.Vector2(); // developer mode

    if (isDev) {
      document.addEventListener('keydown', function (_ref) {
        var key = _ref.key;

        if (key === 'Escape') {
          _this.toggle();
        }
      });
    }
  }

  $pTw7$var$_createClass(THREERoot, [{
    key: "setSize",
    value: function setSize() {
      if (this.aspect) {
        if (this.container.clientWidth / this.container.clientHeight > this.aspect) {
          this.width = this.container.clientHeight * this.aspect;
          this.height = this.container.clientHeight;
        } else {
          this.width = this.container.clientWidth;
          this.height = this.container.clientWidth / this.aspect;
        }
      } else {
        this.width = this.container.clientWidth;
        this.height = this.container.clientHeight;
      }
    }
  }, {
    key: "createOrbitControls",
    value: function createOrbitControls() {
      var _this2 = this;

      if (!THREE.TrackballControls) {
        console.error('TrackballControls.js file is not loaded.');
        return;
      }

      this.controls = new THREE.TrackballControls(this.camera, this.canvas);
      this.addUpdateCallback(function () {
        _this2.controls.update();
      });
    }
  }, {
    key: "start",
    value: function start() {
      var _this3 = this;

      var startTime = this.stopTime || this.firstTime;
      requestAnimationFrame(function (timestamp) {
        _this3.startTime = timestamp - startTime;
        _this3.time = timestamp - _this3.startTime;
      });
      this.tick();
    }
  }, {
    key: "tick",
    value: function tick() {
      var _this4 = this;

      this.update();
      this.render();
      this.animationFrameId = requestAnimationFrame(function (timestamp) {
        _this4.time = timestamp - _this4.startTime;

        _this4.tick();
      });
    }
  }, {
    key: "update",
    value: function update() {
      var time = this.time * this.speed;
      time = this.interval ? time % this.interval : time;
      this.updateCallbacks.forEach(function (fn) {
        fn(time);
      });
    }
  }, {
    key: "render",
    value: function render() {
      this.renderer.render(this.scene, this.camera);
    }
  }, {
    key: "draw",
    value: function draw() {
      this.update();
      this.render();
    }
  }, {
    key: "stop",
    value: function stop() {
      cancelAnimationFrame(this.animationFrameId);
      this.animationFrameId = null;
      this.stopTime = this.time;
    }
  }, {
    key: "reset",
    value: function reset() {
      this.stop();
      this.stopTime = 0;
    }
  }, {
    key: "toggle",
    value: function toggle() {
      this.animationFrameId ? this.stop() : this.start();
    }
  }, {
    key: "addUpdateCallback",
    value: function addUpdateCallback(callback) {
      this.updateCallbacks.push(callback);
    }
  }, {
    key: "addResizeCallback",
    value: function addResizeCallback(callback) {
      this.resizeCallbacks.push(callback);
    }
  }, {
    key: "add",
    value: function add(object, key) {
      key && (this.objects[key] = object);
      this.scene.add(object);
    }
  }, {
    key: "addTo",
    value: function addTo(object, parentKey, key) {
      key && (this.objects[key] = object);
      this.get(parentKey).add(object);
    }
  }, {
    key: "get",
    value: function get(key) {
      return this.objects[key];
    }
  }, {
    key: "remove",
    value: function remove(o) {
      var object;

      if (typeof o === 'string') {
        object = this.objects[o];
      } else {
        object = o;
      }

      if (object) {
        object.parent.remove(object);
        delete this.objects[o];
      }
    }
  }, {
    key: "resize",
    value: function resize() {
      this.container.style.width = '';
      this.container.style.height = '';

      if (this.aspect) {
        this.aspect = this.container.clientWidth / this.container.clientHeight;
      }

      this.setSize();
      this.camera.aspect = this.width / this.height;
      this.camera.updateProjectionMatrix();
      this.renderer.setSize(this.width, this.height);
      this.resizeCallbacks.forEach(function (callback) {
        callback();
      });
    }
  }, {
    key: "initPostProcessing",
    value: function initPostProcessing(passes) {
      var _this5 = this;

      var size = this.renderer.getSize();
      var pixelRatio = this.renderer.getPixelRatio();
      size.width *= pixelRatio;
      size.height *= pixelRatio;
      var composer = this.composer = new THREE.EffectComposer(this.renderer, new THREE.WebGLRenderTarget(size.width, size.height, {
        minFilter: THREE.LinearFilter,
        magFilter: THREE.LinearFilter,
        format: THREE.RGBAFormat,
        stencilBuffer: false
      }));
      var renderPass = new THREE.RenderPass(this.scene, this.camera);
      composer.addPass(renderPass);

      for (var i = 0; i < passes.length; i++) {
        var pass = passes[i];
        pass.renderToScreen = i === passes.length - 1;
        composer.addPass(pass);
      }

      this.renderer.autoClear = false;

      this.render = function () {
        _this5.renderer.clear();

        composer.render();
      };

      this.addResizeCallback(function () {
        composer.setSize(_this5.canvas.clientWidth * pixelRatio, _this5.canvas.clientHeight * pixelRatio);
      });
    }
  }, {
    key: "checkPointer",
    value: function checkPointer(_ref2, meshs, handler, nohandler) {
      var x = _ref2.x,
          y = _ref2.y;
      this.pointer.x = x / this.canvas.clientWidth * 2 - 1;
      this.pointer.y = -(y / this.canvas.clientHeight) * 2 + 1;
      this.raycaster.setFromCamera(this.pointer, this.camera);
      var intersects = this.raycaster.intersectObjects(meshs);

      if (intersects.length > 0) {
        handler(intersects[0].object);
        return true;
      } else {
        nohandler && nohandler();
        return false;
      }
    }
  }]);
  return THREERoot;
}();

function $Moin$export$noop() {}

function $IDtB$var$_toConsumableArray(arr) {
  return $IDtB$var$_arrayWithoutHoles(arr) || $IDtB$var$_iterableToArray(arr) || $IDtB$var$_nonIterableSpread();
}

function $IDtB$var$_nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance");
}

function $IDtB$var$_iterableToArray(iter) {
  if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function $IDtB$var$_arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) {
    for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
      arr2[i] = arr[i];
    }

    return arr2;
  }
}

function $IDtB$var$_typeof(obj) {
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
    $IDtB$var$_typeof = function _typeof(obj) {
      return typeof obj;
    };
  } else {
    $IDtB$var$_typeof = function _typeof(obj) {
      return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
    };
  }

  return $IDtB$var$_typeof(obj);
}

function $IDtB$var$_classCallCheck(instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
}

function $IDtB$var$_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);
  }
}

function $IDtB$var$_createClass(Constructor, protoProps, staticProps) {
  if (protoProps) $IDtB$var$_defineProperties(Constructor.prototype, protoProps);
  if (staticProps) $IDtB$var$_defineProperties(Constructor, staticProps);
  return Constructor;
}

var $IDtB$export$default =
/*#__PURE__*/
function () {
  function Controller(options) {
    $IDtB$var$_classCallCheck(this, Controller);
    var closed = options.closed;
    this.gui = new dat.GUI(options);
    this.gui.closed = closed;
  }
  /**
   * addData
   *
   * @param {Object} data
   * @param {Object} [options={}]
   * @param {function} [options.callback=noop]
   * @param {function} [options.folder=gui]
   * @memberof Controller
   */


  $IDtB$var$_createClass(Controller, [{
    key: "addData",
    value: function addData(data) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var _options$folder = options.folder,
          folder = _options$folder === void 0 ? this.gui : _options$folder,
          _options$callback = options.callback,
          callback = _options$callback === void 0 ? $Moin$export$noop : _options$callback,
          isUniform = options.isUniform;
      var dataKeys = Object.keys(data);
      var datData = {};
      dataKeys.forEach(function (key) {
        datData[key] = data[key].value;
      });
      dataKeys.forEach(function (key) {
        var _data$key = data[key],
            isColor = _data$key.isColor,
            value = _data$key.value,
            range = _data$key.range,
            onChange = _data$key.onChange,
            listen = _data$key.listen;
        var type;

        if (isUniform) {
          switch ($IDtB$var$_typeof(value)) {
            case 'boolean':
              type = '1i';
              break;

            case 'array':
              type = value.length + 'f';
              break;

            case 'object':
              type = 't';
              break;

            default:
              type = '1f';
              break;
          }
        }

        var controller;

        if (isColor) {
          controller = folder.addColor(datData, key);
        } else {
          var guiRange = [];

          if (range) {
            guiRange = range;
          } else if (key === 'frame') {
            guiRange = [0, 1];
          } else if (typeof value === 'number') {
            if (value < 1 && value >= 0) {
              guiRange = [0, 1];
            } else {
              var diff = Math.pow(10, String(Math.floor(value)).length - 1) * 2;
              guiRange = [value - diff, value + diff];
            }
          }

          controller = folder.add.apply(folder, [datData, key].concat($IDtB$var$_toConsumableArray(guiRange)));
        }

        onChange && controller.onChange(function (value) {
          onChange(value);
        });
        listen && controller.listen();
        callback(key, {
          type: type,
          value: value
        });
      });
      return datData;
    }
  }, {
    key: "addUniformData",
    value: function addUniformData(data) {
      var uniforms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
      return this.addData(data, {
        callback: function callback(key, obj) {
          uniforms[key] = obj;
        },
        folder: options.folder,
        isUniform: true
      });
    }
  }, {
    key: "addFolder",
    value: function addFolder(name, isClosed) {
      var folder = this.gui.addFolder(name);
      !isClosed && folder.open();
      return folder;
    }
  }]);
  return Controller;
}();

// ASSET: scripts/modules/easing.js
var $JJyr$exports = {};
/*!
 * Terms of Use: Easing Functions (Equations)
 *
 * Open source under the MIT License and the 3-Clause BSD License.
 * Copyright © 2001 Robert Penner
 * http://robertpenner.com/easing_terms_of_use.html
 */

/**
 * linear
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */

function $JJyr$export$linear(t, b, c, d) {
  return c * t / d + b;
}
/**
 * easeInQuad
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.linear = $JJyr$export$linear;

function $JJyr$export$easeInQuad(t, b, c, d) {
  return c * (t /= d) * t + b;
}
/**
 * easeOutQuad
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInQuad = $JJyr$export$easeInQuad;

function $JJyr$export$easeOutQuad(t, b, c, d) {
  return -c * (t /= d) * (t - 2) + b;
}
/**
 * easeInOutQuad
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutQuad = $JJyr$export$easeOutQuad;

function $JJyr$export$easeInOutQuad(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * t * t + b;
  return -c / 2 * (--t * (t - 2) - 1) + b;
}
/**
 * easeInCubic
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutQuad = $JJyr$export$easeInOutQuad;

function $JJyr$export$easeInCubic(t, b, c, d) {
  return c * Math.pow(t / d, 3) + b;
}
/**
 * easeOutCubic
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInCubic = $JJyr$export$easeInCubic;

function $JJyr$export$easeOutCubic(t, b, c, d) {
  return c * (Math.pow(t / d - 1, 3) + 1) + b;
}
/**
 * easeInOutCubic
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutCubic = $JJyr$export$easeOutCubic;

function $JJyr$export$easeInOutCubic(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * Math.pow(t, 3) + b;
  return c / 2 * (Math.pow(t - 2, 3) + 2) + b;
}
/**
 * easeInQuart
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutCubic = $JJyr$export$easeInOutCubic;

function $JJyr$export$easeInQuart(t, b, c, d) {
  return c * Math.pow(t / d, 4) + b;
}
/**
 * easeOutQuart
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInQuart = $JJyr$export$easeInQuart;

function $JJyr$export$easeOutQuart(t, b, c, d) {
  return -c * (Math.pow(t / d - 1, 4) - 1) + b;
}
/**
 * easeInOutQuart
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutQuart = $JJyr$export$easeOutQuart;

function $JJyr$export$easeInOutQuart(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * Math.pow(t, 4) + b;
  return -c / 2 * (Math.pow(t - 2, 4) - 2) + b;
}
/**
 * easeInQuint
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutQuart = $JJyr$export$easeInOutQuart;

function $JJyr$export$easeInQuint(t, b, c, d) {
  return c * Math.pow(t / d, 5) + b;
}
/**
 * easeOutQuint
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInQuint = $JJyr$export$easeInQuint;

function $JJyr$export$easeOutQuint(t, b, c, d) {
  return c * (Math.pow(t / d - 1, 5) + 1) + b;
}
/**
 * easeInOutQuint
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutQuint = $JJyr$export$easeOutQuint;

function $JJyr$export$easeInOutQuint(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * Math.pow(t, 5) + b;
  return c / 2 * (Math.pow(t - 2, 5) + 2) + b;
}
/**
 * easeInSine
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutQuint = $JJyr$export$easeInOutQuint;

function $JJyr$export$easeInSine(t, b, c, d) {
  return c * (1 - Math.cos(t / d * (Math.PI / 2))) + b;
}
/**
 * easeOutSine
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInSine = $JJyr$export$easeInSine;

function $JJyr$export$easeOutSine(t, b, c, d) {
  return c * Math.sin(t / d * (Math.PI / 2)) + b;
}
/**
 * easeInOutSine
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutSine = $JJyr$export$easeOutSine;

function $JJyr$export$easeInOutSine(t, b, c, d) {
  return c / 2 * (1 - Math.cos(Math.PI * t / d)) + b;
}
/**
 * easeInExpo
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutSine = $JJyr$export$easeInOutSine;

function $JJyr$export$easeInExpo(t, b, c, d) {
  return c * Math.pow(2, 10 * (t / d - 1)) + b;
}
/**
 * easeOutExpo
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInExpo = $JJyr$export$easeInExpo;

function $JJyr$export$easeOutExpo(t, b, c, d) {
  return c * (-Math.pow(2, -10 * t / d) + 1) + b;
}
/**
 * easeInOutExpo
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutExpo = $JJyr$export$easeOutExpo;

function $JJyr$export$easeInOutExpo(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
}
/**
 * easeInCirc
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInOutExpo = $JJyr$export$easeInOutExpo;

function $JJyr$export$easeInCirc(t, b, c, d) {
  return c * (1 - Math.sqrt(1 - (t /= d) * t)) + b;
}
/**
 * easeOutCirc
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeInCirc = $JJyr$export$easeInCirc;

function $JJyr$export$easeOutCirc(t, b, c, d) {
  return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
}
/**
 * easeInOutCirc
 *
 * @param {number} t time: 現在時刻 (0 ~ duration)
 * @param {number} b begin: 開始位置
 * @param {number} c change: 開始位置から終了位置までの変化量 (finish - begin)
 * @param {number} d duration: 全体時間
 * @returns {number} 現在位置
 */


$JJyr$exports.easeOutCirc = $JJyr$export$easeOutCirc;

function $JJyr$export$easeInOutCirc(t, b, c, d) {
  if ((t /= d / 2) < 1) return c / 2 * (1 - Math.sqrt(1 - t * t)) + b;
  return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
}

$JJyr$exports.easeInOutCirc = $JJyr$export$easeInOutCirc;
var $JJyr$export$easingList = ['linear', 'easeInSine', 'easeOutSine', 'easeInOutSine', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInQuart', 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', 'easeOutQuint', 'easeInOutQuint', 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeInCirc', 'easeOutCirc', 'easeInOutCirc'];
$JJyr$exports.easingList = $JJyr$export$easingList;

function $Zk$var$_classCallCheck(instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
}

function $Zk$var$_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);
  }
}

function $Zk$var$_createClass(Constructor, protoProps, staticProps) {
  if (protoProps) $Zk$var$_defineProperties(Constructor.prototype, protoProps);
  if (staticProps) $Zk$var$_defineProperties(Constructor, staticProps);
  return Constructor;
}
/**
 * アニメーション関数
 *
 * @param {AnimationCallback} fn アニメーションフレーム毎に実行するコールバック
 * @param {Object} [options={}] オプション
 * @param {number} [options.begin=0] 開始位置
 * @param {number} [options.finish=1] 終了位置
 * @param {number} [options.duration=500] 全体時間
 * @param {string} [options.easing='easeInOutCubic'] Easing function
 */


function $Zk$export$animate(fn) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[.........完整代码请登录后点击上方下载按钮下载查看

网友评论0