Home  >  Article  >  Web Front-end  >  Loading animation special effects based on HTML5 Canvas and Rebound animation

Loading animation special effects based on HTML5 Canvas and Rebound animation

黄舟
黄舟Original
2017-01-19 13:52:402066browse

Brief Tutorial

This is a Loading animation special effect based on HTML5 canvas and Rebound animation. The loading animation uses a canvas to cover the entire page and displays a polygonal loading loader to represent the loading progress.

1. Create a SpringSystem.

// Create a SpringSystem.
  let springSystem = new rebound.SpringSystem();

2. Add a spring to the system.

// Add a spring to the system.
  demo.spring = springSystem.createSpring(settings.tension, settings.friction);

3. Add SpringListener event monitoring for spring.

_addSpringListener() {
 
  let ctx = this;
 
  // Add a listener to the spring. Every time the physics
  // solver updates the Spring's value onSpringUpdate will
  // be called.
  this._spring.addListener({
    // ...
  });
}

4. Set the end animation value of the spring, and the parameter is the current value of the start animation.

this._spring.setEndValue((this._spring.getCurrentValue() === 1) ? 0 : 1);

5. Set the animation progress in the onSpringUpdate callback function.

onSpringUpdate(spring) {
 
  let val = spring.getCurrentValue();
 
  // Input range in the `from` parameters.
  let fromLow = 0,
    fromHigh = 1,
    // Property animation range in the `to` parameters.
    toLow = ctx._springRangeLow,
    toHigh = ctx._springRangeHigh;
 
  val = rebound.MathUtil.mapValueInRange(val, fromLow, fromHigh, toLow, toHigh);
 
  // Note that the render method is
  // called with the spring motion value.
  ctx.render(val);
}

The above is the content of Loading animation special effects based on HTML5 Canvas and Rebound animation. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn