index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
  6. <title>Pasition - Path Transition with little JS code, render to anywhere.</title>
  7. <style>
  8. html,body{
  9. padding:0;
  10. margin: 0;
  11. overflow: hidden;
  12. }
  13. canvas{
  14. padding:0;
  15. margin: 0;
  16. border: 0;
  17. }
  18. #container{
  19. text-align: center;
  20. }
  21. </style>
  22. <style>
  23. body {
  24. background-color: #1e1d23;
  25. /*opacity: 0;*/
  26. display: -webkit-box;
  27. display: -ms-flexbox;
  28. display: flex;
  29. -webkit-box-orient: vertical;
  30. -webkit-box-direction: normal;
  31. -ms-flex-direction: column;
  32. flex-direction: column;
  33. -webkit-box-pack: center;
  34. -ms-flex-pack: center;
  35. justify-content: center;
  36. text-transform: uppercase;
  37. font-size: 12px;
  38. letter-spacing: 2px;
  39. -webkit-tap-highlight-color: rgba(0,0,0,0);
  40. -webkit-user-select: none;
  41. -moz-user-select: none;
  42. -ms-user-select: none;
  43. user-select: none;
  44. }
  45. /*body.ready { opacity: 1; }*/
  46. .icon-text path,
  47. .icon-text polygon {
  48. /*opacity: 0;*/
  49. }
  50. .info {
  51. text-align: center;
  52. }
  53. .description {
  54. /*opacity: 0;*/
  55. color: white;
  56. margin-top: 10px;
  57. }
  58. .links {
  59. display: -webkit-box;
  60. display: -ms-flexbox;
  61. display: flex;
  62. -webkit-box-orient: vertical;
  63. -webkit-box-direction: normal;
  64. -ms-flex-direction: column;
  65. flex-direction: column;
  66. -webkit-box-pack: center;
  67. -ms-flex-pack: center;
  68. justify-content: center;
  69. -webkit-box-align: center;
  70. -ms-flex-align: center;
  71. align-items: center;
  72. margin-top: 20px;
  73. }
  74. @media (min-width: 700px) {
  75. .links {
  76. -webkit-box-orient: horizontal;
  77. -webkit-box-direction: normal;
  78. -ms-flex-direction: row;
  79. flex-direction: row;
  80. }
  81. }
  82. .button {
  83. /*opacity: 0;*/
  84. position: relative;
  85. display: -webkit-box;
  86. display: -ms-flexbox;
  87. display: flex;
  88. -webkit-box-orient: vertical;
  89. -webkit-box-direction: normal;
  90. -ms-flex-direction: column;
  91. flex-direction: column;
  92. -webkit-box-pack: center;
  93. -ms-flex-pack: center;
  94. justify-content: center;
  95. width: 180px;
  96. height: 60px;
  97. text-decoration: none;
  98. }
  99. .button.blue {
  100. color: #5E89FB;
  101. }
  102. .button.green {
  103. color: #18F38C;
  104. }
  105. .button.red {
  106. color: #FF1461;
  107. }
  108. .button svg {
  109. position: absolute;
  110. left: 0;
  111. top: 0;
  112. right: 0;
  113. bottom: 0;
  114. stroke-width: 1;
  115. fill: none;
  116. fill-rule: evenodd;
  117. stroke: currentColor;
  118. }
  119. .button.green svg {
  120. -webkit-transform: rotate(180deg);
  121. transform: rotate(180deg);
  122. }
  123. .button path {
  124. scale: .9;
  125. transform-origin: 50% 50%;
  126. }
  127. .credits {
  128. /*opacity: 0;*/
  129. margin-top: 20px;
  130. color: #979797;
  131. }
  132. .credits a {
  133. position: relative;
  134. color: currentColor;
  135. text-decoration: none;
  136. }
  137. .credits a:after {
  138. content: "";
  139. /*opacity: 0;*/
  140. display: block;
  141. position: absolute;
  142. left: 0;
  143. bottom: -3px;
  144. width: 100%;
  145. border-bottom: 1px solid currentColor;
  146. transition: opacity .75s ease;
  147. }
  148. /*.credits a:hover:after {
  149. opacity: 1;
  150. transition: opacity .25s ease;
  151. }*/
  152. .credits a,
  153. .credits span {
  154. transition: color .75s ease;
  155. }
  156. .credits a:hover,
  157. .highlighted {
  158. color: white;
  159. transition: color .25s ease;
  160. }
  161. #container{
  162. /*margin-top:100px ;*/
  163. }
  164. @media only screen and (max-width: 500px) {
  165. canvas{
  166. width: 100%;
  167. }
  168. }
  169. </style>
  170. </head>
  171. <body>
  172. <div style="display: none;">
  173. <svg xmlns="http://www.w3.org/2000/svg" >
  174. <path id="pathA" d="M280,250A200,200,0,1,1,680,250A200,200,0,1,1,280,250Z"></path>
  175. <path id="pathF" 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>
  176. <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
  177. 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>
  178. <path id="pathC" 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.7-39.3,5.9-49.2,16.7c-7.9,8.9,0,40.3,0,46.2c0,6-3,33.5-4.9,40.4c-1,5.9,0,9.8-1,13.8c-1,3,6,3.9,6,3.9s-6,7.8-8.9,5.9c-2.9-1-4.9-1-6.9,0c-2,0-5.9,1.9-9.9,0L232.9,401c2,1,4.9,1.9,7.9,1c4-1,23.6-9.9,25.6-11.9c2.9-1,19.7-10.8,22.6-16.7c2-5.9,5.9-24.6,5.9-30.5c1-6,2-24.6,2-29.5s-1-13.8,0-17.7c2-2.9,4.9-6.9,8.9-8.9c4.9-1,10.8-1,11.8-1c2,0,18.7,2,21.6,2c3.9,0,19.7-2.9,23.6-5c4.9-0.9,7.8,0,8.9,2c2,1.9-2,4.9-2,5.9c-1,1-8.8,10.8-10.8,14.7c-2,4.9-8.8,13.8-6.9,17.7c2,3.9,2,4.9,7.8,7.9c5.9,1.9,28.5,13.8,41.3,25.6c13.8,12.7,26.6,28.4,28.6,36.4c2.9,8.9,7.8,9.8,10.8,9.8c3,1,8.9,2,8.9,5.9s-1,8.8-1,8.8l36.4,13.8c0,0,0-12.8-1-17.7c-1-5.9-6.9-11.8-11.8-17.7c-4.9-6.9-56-57.1-61-61c-4.9-3-8.9-6.9-9.8-14.7c-1-7.9,8.8-13.8,14.8-20.6c3.9-4.9,14.7-27.6,16.7-30.6c2-2.9,8.9-10.8,12.8-10.8c4.9,0,15.8,6.9,29.5,11.8c5.9,2,48.2,12.8,54.1,14.8c5.9,1,18.6,0,22.6,3.9c3.9,2.9,0,10.9-1,15.8c-1,5.9-11.8,27.5-11.8,27.5s2,7.8,2,13.8c0,6.9-2.9,31.5-5.9,39.3c-2,8.9-15.8,31.6-18.7,35.5c-2,2.9-4.9,4.9-4.9,9.9c0,4.9,8.8,6,11.8,9.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7.9-7.8-7.9-12.7s-2-17.7-2-17.7s-6.9-1-9.8,1.9c-2.9,2-9.8,17.8-13.8,17.8c-10.9-2-24.6,1-24.6,2.9c1,2.9,10.8,1,10.8,1c0,1-3.9,5.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>
  179. <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
  180. c0,0,11.4-89.5,15.8-191h210.2l11.9,191h22.1c0,0-5.3-96.6-0.6-205.7H638.9z"></path>
  181. <path id="pathE" d="M345.47,250L460.94,450L230,450Z M460.94,50L576.41,250L345.47,250Z M576.41,250L691.88,450L460.94,450Z"></path>
  182. </svg>
  183. </div>
  184. <div id="container" >
  185. <canvas id="canvas" width="960" height="500" ></canvas>
  186. </div>
  187. <div class="info">
  188. <p class="description">
  189. Pasition - Path Transition with little JS code, render to anywhere.
  190. </p>
  191. <div class="links">
  192. <a class="button green" href="https://github.com/AlloyTeam/pasition" target="_blank">
  193. <svg viewBox="0 0 180 60">
  194. <path d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"></path>
  195. </svg>
  196. <span>GitHub</span>
  197. </a>
  198. <a class="button blue" href="javascript:" onclick="toogleStroke()">
  199. <svg viewBox="0 0 180 60">
  200. <path d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"></path>
  201. </svg>
  202. <span id="mode" >Stroke</span>
  203. </a>
  204. <a class="button red" href="https://github.com/AlloyTeam/pasition#usage" target="_blank">
  205. <svg viewBox="0 0 180 60">
  206. <path d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"></path>
  207. </svg>
  208. <span>DOCS</span>
  209. </a>
  210. </div>
  211. <p class="credits">
  212. v<span class="version">1.0</span> © <span class="date">2019</span> dntzhang
  213. </p>
  214. </div>
  215. <script src="./dist/pasition.js"></script>
  216. <script>
  217. var stroke = false
  218. function renderCurve(context,points,color){
  219. context.beginPath();
  220. context.strokeStyle = color||'black';
  221. context.moveTo(points[0], points[1]);
  222. context.bezierCurveTo(points[2], points[3], points[4], points[5], points[6], points[7]);
  223. context.stroke();
  224. }
  225. function renderShapes(context,curves,color){
  226. context.beginPath();
  227. context.fillStyle = color||'black';
  228. context.moveTo(curves[0][0], curves[0][1]);
  229. curves.forEach(function(points){
  230. context.bezierCurveTo(points[2], points[3], points[4], points[5], points[6], points[7]);
  231. })
  232. context.closePath();
  233. context.fill();
  234. }
  235. function toogleStroke() {
  236. stroke = !stroke
  237. document.querySelector('#mode').innerHTML = stroke ? 'Fill' : 'Stroke'
  238. }
  239. var pathA = document.querySelector('#pathA').getAttribute('d'),
  240. pathB= document.querySelector('#pathB').getAttribute('d'),
  241. pathC= document.querySelector('#pathC').getAttribute('d'),
  242. pathD= document.querySelector('#pathD').getAttribute('d'),
  243. pathF= document.querySelector('#pathF').getAttribute('d'),
  244. pathE= document.querySelector('#pathE').getAttribute('d')
  245. var canvas = document.getElementById('canvas'),
  246. context = canvas.getContext('2d')
  247. function animate(arr,indexA,indexB){
  248. pasition.animate({
  249. from: arr[indexA],
  250. to: arr[indexB],
  251. time: 1500,
  252. progress:function(shapes){
  253. context.clearRect(0, 0, canvas.width, canvas.height)
  254. shapes.forEach(function(curves){
  255. if(stroke) {
  256. curves.forEach(function (curve) {
  257. renderCurve(context, curve, "#006DF0")
  258. })
  259. }else{
  260. renderShapes(context,curves,"#006DF0")
  261. }
  262. })
  263. },
  264. end:function(){
  265. setTimeout(function(){
  266. indexA++
  267. indexB++
  268. if(indexA===arr.length)indexA = 0
  269. if(indexB===arr.length)indexB = 0
  270. animate(arr,indexA,indexB)
  271. },1500)
  272. }
  273. })
  274. }
  275. animate([pathA,pathB,pathE,pathB,pathD,pathC,pathF,pathC,pathD,pathB,pathA],0,1)
  276. </script>
  277. </body>
  278. </html>