bb84d9199fe94cdf05c8b51273c1d6a06782dc1c7e74f299db98751e94f02d25cdd2add4da4d673d1eb45639a84569871a45776952695c776e62096ebc7729 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf8" />
  5. <title>Rect</title>
  6. <style>
  7. html, body, #canvas {
  8. width: 100%;
  9. height: 100%;
  10. margin: 0px;
  11. padding: 0px;
  12. }
  13. </style>
  14. <script src="../../dist/crender.map.js"></script>
  15. </head>
  16. <body>
  17. <canvas id="canvas"></canvas>
  18. </body>
  19. <script>
  20. const { CRender, extendNewGraph } = window.CRender
  21. const render = new CRender(document.querySelector('#canvas'))
  22. const [w, h] = render.area
  23. const rect = render.add({
  24. name: 'rect',
  25. animationCurve: 'easeOutCubic',
  26. animationFrame: 50,
  27. drag: true,
  28. hover: true,
  29. shape: {
  30. x: w / 2 - 100,
  31. y: h / 2 - 50,
  32. w: 200,
  33. h: 100
  34. },
  35. style: {
  36. fill: '#ffee97',
  37. stroke: 'goldenrod',
  38. lineWidth: 2
  39. }
  40. })
  41. function wait (time) {
  42. return new Promise(resolve => setTimeout(resolve, time))
  43. }
  44. async function start () {
  45. await wait(1000)
  46. await rect.animation('shape', {
  47. x: w / 2 - 200,
  48. w: 400
  49. })
  50. await wait(1000)
  51. rect.animation('style', {
  52. fill: 'lemonchiffon'
  53. })
  54. }
  55. start()
  56. </script>
  57. </html>