Home > Web Front-end > H5 Tutorial > body text

Loading animation special effects based on HTML5 Canvas and Rebound animation

黄舟
Release: 2017-01-19 13:52:40
Original
2029 people have browsed it

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();
Copy after login

2. Add a spring to the system.

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

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({
    // ...
  });
}
Copy after login

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);
Copy after login

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);
}
Copy after login

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 (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!