svg.html 7.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <html>
  2. <body>
  3. <svg xmlns="http://www.w3.org/2000/svg" style="width: 100%;height: 1000px;">
  4. <defs>
  5. <path id="pathA" d="M280,250A200,200,0,1,1,680,250A200,200,0,1,1,280,250Z"></path>
  6. <path id="pathF"
  7. d="M480,50L423.8,182.6L280,194.8L389.2,289.4L356.4,430L480,355.4L480,355.4L603.6,430L570.8,289.4L680,194.8L536.2,182.6Z"></path>
  8. <path id="pathB" d="M480,437l-29-26.4c-103-93.4-171-155-171-230.6c0-61.6,48.4-110,110-110c34.8,0,68.2,16.2,90,41.8
  9. C501.8,86.2,535.2,70,570,70c61.6,0,110,48.4,110,110c0,75.6-68,137.2-171,230.8L480,437z"></path>
  10. <path id="pathC"
  11. d="M595,82.1c1,1-1,2-1,2s-6.9,2-8.9,4.9c-2,2-4.9,8.8-4.9,8.8c3.9-1,8.9-2,13.8-4c1,0,2,1,3,2c1,0-11.8,4.9-14.8,6.9c-2,2-11.8,9.9-14.8,9.9c-2.9,0-9.9,1-9.9,1c1,2,2,3.9,3.9,6.9c0,0-6.9,4-6.9,4.9c-1,1-5.9,6.9-5.9,6.9s17.7,1.9,23.6-7.9c-5.9,9.8-19.7,19.7-48.2,19.7c-29.5,0-53.1-11.8-68.9-17.7c-16.7-6.9-38.4-14.8-56.1-14.8c-16.7,0-36.4,4.9-49.2,16.8c-22.6-8.8-54.1-4-68.9,9.8c-13.8,13.8-27.5,30.5-29.5,42.3c-2.9,12.9-9.8,43.3-19.7,57.2c-13.8,22.5-29.5,28.5-34.5,38.3c-4.9,9.9-4.9,30.5-4,30.5c2,1,8.9,0,12.8-2c7.9-2.9,29.5-25.6,37.4-36.4c7.9-10.9,34.5-58.1,38.4-74.8s7.9-33.5,19.7-42.3c12.8-8.8,28.5-4.9,28.5-3.9c0,0-14.7,11.8-15.7,44.3s18.7,28.6,8.8,49.2c-9.9,17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9-6.9,5.9c-2,0-7.8,2-8.8,2.9c-2,0-5.9,3.1-5.9,3.1c2.9,0,5.9,0,9.8,0.9c0,0-5.9,4-8.9,4c-2.9,0-12.8,2.9-15.7,3.9c-2,1.9-9.9,7.9-9.9,7.9H589l1,2h4.9L595,82.1L595,82.1z"></path>
  12. <path id="pathD" d="M638.9,259.3v-23.8H380.4c-0.7-103.8-37.3-200.6-37.3-200.6s-8.5,0-22.1,0C369.7,223,341.4,465,341.4,465h22.1
  13. c0,0,11.4-89.5,15.8-191h210.2l11.9,191h22.1c0,0-5.3-96.6-0.6-205.7H638.9z"></path>
  14. <path id="pathE"
  15. d="M345.47,250L460.94,450L230,450Z M460.94,50L576.41,250L345.47,250Z M576.41,250L691.88,450L460.94,450Z"></path>
  16. <path id="pathG"
  17. d="M280,250A200,200,0,1,1,680,250A200,200,0,1,1,280,250Z M320,290A160,160,0,1,1,640,210A160,160,0,1,1,320,290Z"></path>
  18. </defs>
  19. <path id="dom" stroke="black" fill="transparent"/>
  20. </svg>
  21. <a href="https://github.com/AlloyTeam/pasition" target="_blank" style="position: absolute;z-index: 1000; right: 0; top: 0;">
  22. <img src="//alloyteam.github.io/omi/asset/github.png" alt="" />
  23. </a>
  24. <script src="https://unpkg.com/pasition@1.0.1/dist/pasition.js"></script>
  25. <script>
  26. /**
  27. * 一个对pasition的扩展,pasition执行过程中产生的实时返回数据(即shapes)格式对于生成canvas画布数据比较方便,但对于生成svg需要额外的处理一下,这里扩展的这个方法是将实时数据生成适合svg路径的字符串格式
  28. * @param {Object} shapes pasition执行过程中产生的实时返回数据
  29. * @return {String} SVGString svg路径格式字符串
  30. * */
  31. pasition.toSVGString = function (shapes) {
  32. /*克隆一下实时数据*/
  33. //var shapes = JSON.parse(JSON.stringify(shapes||[]));
  34. /*对数据中的每个点数组做处理
  35. * */
  36. return shapes.map(function(shape){
  37. shape.forEach(function (point, idx) {
  38. if (!idx) {
  39. /*
  40. * 若是第一个点数组,那么对该点数组的处理是前面加M,然后前两个点后面加C
  41. * */
  42. point.splice(2, 0, "C");
  43. point.unshift("M");
  44. } else {
  45. /*
  46. * 除了第一个点数据外,所有的点数组的前两个点删除掉
  47. * */
  48. point.splice(0, 2, "C");
  49. }
  50. });
  51. return shape.map(function (point) {
  52. return point.join(" ");
  53. }).join("");
  54. }).join("")
  55. };
  56. var dom = document.querySelector("#dom");
  57. var pathA = document.querySelector('#pathA').getAttribute('d'),
  58. pathB = document.querySelector('#pathB').getAttribute('d'),
  59. pathC = document.querySelector('#pathC').getAttribute('d'),
  60. pathD = document.querySelector('#pathD').getAttribute('d'),
  61. pathF = document.querySelector('#pathF').getAttribute('d'),
  62. pathE = document.querySelector('#pathE').getAttribute('d'),
  63. pathG = document.querySelector('#pathG').getAttribute('d');
  64. function animate(arr, indexA, indexB) {
  65. pasition.animate({
  66. from: arr[indexA],
  67. to: arr[indexB],
  68. time: 1500,
  69. progress: function (shapes) {
  70. dom.setAttribute("d", pasition.toSVGString(shapes));
  71. },
  72. end: function () {
  73. setTimeout(function () {
  74. indexA++
  75. indexB++
  76. if (indexA === arr.length)indexA = 0
  77. if (indexB === arr.length)indexB = 0
  78. animate(arr, indexA, indexB)
  79. }, 1500)
  80. }
  81. })
  82. }
  83. animate([pathA, pathB, pathC, pathD, pathE, pathF, pathG], 0, 1)
  84. </script>
  85. </body>
  86. </html>