To

使用 m-to 运动一切。

在 Omi 中使用

  1. <m-to
  2. from={{ number: 1 }}
  3. to={{ number: 100 }}
  4. duration={600}
  5. easing='bounce-in'
  6. out={this.out}
  7. delay={200}
  8. onProgress={this.onProgress}
  9. onBegin={this.onProgress}
  10. onEnd={this.onEnd}>
  11. </m-to>

API

Props

  1. {
  2. from: object;
  3. to: object;
  4. duration: number;
  5. out: object;
  6. delay: number;
  7. //easing graphs http://tweenjs.github.io/tween.js/examples/03_graphs.html
  8. easing: "quadratic-in" | "quadratic-out" | "quadratic-in-out" | "cubic-in" | "cubic-out" | "cubic-in-out" | "quartic-in" | "quartic-out" | "quartic-in-out" | "quintic-in" | "quintic-out" | "quintic-in-out" | "sinusoidal-in" | "sinusoidal-out" | "sinusoidal-in-out" | "exponential-in" | "exponential-out" | "exponential-in-out" | "circular-in" | "circular-out" | "circular-in-out" | "elastic-in" | "elastic-out" | "elastic-in-out" | "back-in" | "back-out" | "back-in-out" | "bounce-in" | "bounce-out" | "bounce-in-out";
  9. start: boolean;
  10. }

Demo

  1. import { define, WeElement, render, h } from 'omi'
  2. import 'omim/to'
  3. define('my-app', class extends WeElement {
  4. number = 2
  5. from = this.number
  6. to = this.number
  7. out = {
  8. number: this.number
  9. }
  10. onInput = (e) => {
  11. this.to = Number(e.target.value)
  12. this.from = this.out.number
  13. this.number = this.to
  14. this.update()
  15. }
  16. onProgress = () => {
  17. this.update()
  18. }
  19. onClick = () => {
  20. this.start = true
  21. this.update()
  22. }
  23. start = false
  24. outs = [{ width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }]
  25. render() {
  26. return (
  27. <div>
  28. <h3>Simple</h3>
  29. <input type='number' onInput={this.onInput} value={this.number} step={2}></input>
  30. <div>{this.out.number.toFixed(0)}</div>
  31. <div>{this.out.number.toFixed(0)}*{this.out.number.toFixed(0)}={(this.out.number * this.out.number).toFixed(0)}</div>
  32. <div style={{ width: this.out.number * 5 + 'px', background: 'red', height: '5px' }}></div>
  33. <m-to from={{ number: this.from }} easing='bounce-in' onProgress={this.onProgress} to={{ number: this.to }} out={this.out} duration={1000}>
  34. </m-to>
  35. <h3>Group</h3>
  36. {this.outs.map((item, index) =>
  37. <div style={{ marginTop: '5px', width: this.outs[index].width + 'px', background: 'red', height: '5px' }}></div>
  38. )}
  39. <button onClick={this.onClick}>Play</button>
  40. {this.outs.map((item, index) =>
  41. <m-to from={{ width: 10 }} start={this.start} easing="bounce-out" delay={100 * index} onProgress={this.onProgress} to={{ width: 200 }} out={this.outs[index]} duration={600}>
  42. </m-to>
  43. )}
  44. </div>
  45. )
  46. }
  47. })
  48. render(<my-app />, 'body')