218bc2c05aea4839f6266188759c0699ac23a4dddda6f71902dbac3bd618bc34be357cc50cf8ecc8e468b348e8074c25f3a8570e026bde3b0de3759df1ab66 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf8" />
  5. <title>Polyline</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 topPos = h / 3
  24. const bottom = h / 3 * 2
  25. const gap = w / 10
  26. const beginX = w / 2 - gap * 2
  27. const points = new Array(5).fill('').map((t, i) =>
  28. [beginX + gap * i, i % 2 === 0 ? topPos : bottom])
  29. const pointsAfter = new Array(5).fill('').map((t, i) =>
  30. [beginX + gap * i, i % 2 === 0 ? bottom : topPos])
  31. const polyline = render.add({
  32. name: 'polyline',
  33. animationCurve: 'easeOutCubic',
  34. animationFrame: 50,
  35. drag: true,
  36. hover: true,
  37. shape: {
  38. points
  39. },
  40. style: {
  41. stroke: '#ffee97',
  42. lineWidth: 30
  43. }
  44. })
  45. function wait (time) {
  46. return new Promise(resolve => setTimeout(resolve, time))
  47. }
  48. async function start () {
  49. await wait(1000)
  50. await polyline.animation('shape', {
  51. points: pointsAfter
  52. })
  53. await wait(1000)
  54. polyline.animation('style', {
  55. stroke: 'lemonchiffon'
  56. })
  57. }
  58. start()
  59. </script>
  60. </html>