1. 程式人生 > >web前端案例:貪吃蛇小遊戲

web前端案例:貪吃蛇小遊戲

640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1

0?wx_fmt=gif&wxfrom=5&wx_lazy=1

貪吃蛇小遊戲原始碼
  1. <!doctype html>

  2. <html lang="en">

  3. <head>

  4. <!--網站編碼格式,UTF-8 國際編碼,GBK或 gb2312 中文編碼-->

  5. <meta charset="UTF-8">

  6. <meta name="Keywords" content="關鍵詞一,關鍵詞二">

  7. <meta name="Description" content="網站描述內容">

  8. <title>Document</title>

  9. <style>

  10. html {

  11. background: #8D946A

    ;

  12. }

  13. pattern path {

  14. stroke: #8D946A;

  15. }

  16. .snake-group {

  17. stroke: #292A18;

  18. }

  19. .snake {

  20. -webkit-animation: stroke-anim 4s linear infinite;

  21. animation: stroke-anim 4s linear infinite;

  22. }

  23. @-webkit-keyframes stroke-anim {

  24. to {

  25. stroke-dashoffset: 0;

  26. }

  27. }

  28. @keyframes stroke-anim {

  29. to {

  30. stroke-dashoffset: 0;

  31. }

  32. }

  33. /* Values generated from JS */

  34. .snake {

  35. stroke-dasharray: 32 224;

  36. stroke-dashoffset: 256;

  37. -webkit-animation-timing-function: steps(32);

  38. animation-timing-function: steps(32);

  39. }

  40. /* ////////////////////////////////////////////////////////////////////////// */

  41. .dot {

  42. -webkit-animation: dot1 4s steps(1) infinite;

  43. animation: dot1 4s steps(1) infinite;

  44. }

  45. @-webkit-keyframes dot1 {

  46. 0%,

  47. 26%,

  48. 91.1% {

  49. opacity: 1;

  50. }

  51. 26.1%,

  52.  91% {

  53. opacity

    : 0;

  54. }

  55. }

  56. @keyframes dot1 {

  57. 0%,

  58. 26%,

  59. 91.1% {

  60. opacity: 1;

  61. }

  62. 26.1%,

  63. 91% {

  64. opacity: 0;

  65. }

  66. }

  67. .dot-2 {

  68. -webkit-animation-name: dot2;

  69. animation-name: dot2;

  70. }

  71. @-webkit-keyframes dot2 {

  72. 0%,

  73. 26%,

  74. 51%,

  75. 100% {

  76. opacity: 0;

  77. }

  78. 26.1%,

  79.  50% {

  80. opacity: 1;

  81. }

  82. }

  83. @keyframes dot2 {

  84. 0%,

  85. 26%,

  86. 51%,

  87. 100% {

  88. opacity: 0;

  89. }

  90. 26.1%,

  91. 50% {

  92. opacity: 1;

  93. }

  94. }

  95. .dot-3 {

  96. -webkit-animation-name: dot3;

  97. animation-name: dot3;

  98. }

  99. @-webkit-keyframes dot3 {

  100. 0%,

  101. 50%,

  102. 92%,

  103. 100% {

  104. opacity: 0;

  105. }

  106. 50.1%,

  107.  92% {

  108. opacity: 1;

  109. }

  110. }

  111. @keyframes dot3 {

  112. 0%,

  113. 50%,

  114. 92%,

  115. 100% {

  116. opacity: 0;

  117. }

  118. 50.1%,

  119. 92% {

  120. opacity: 1;

  121. }

  122. }

  123. svg {

  124. position: absolute;

  125. top: 0;

  126. right: 0;

  127. bottom: 0;

  128. left: 0;

  129. margin: auto;

  130. max-width: 144px;

  131. max-height: 90vh;

  132. }

  133. </style>

  134. </head>

  135. <body>

  136. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-8 -8 64 84" shape-rendering="crispEdges">

  137. <defs>

  138. <pattern id="pattern" width="8" height="8" patternUnits="userSpaceOnUse" x="-4" y="-4">

  139. <path d="M 0 0 L8 0 8 8 0 8 z" fill="none"></path>

  140. </pattern>

  141. </defs>

  142. <g

  143. class="snake-group"

  144. stroke-linejoin="miter"

  145. stroke-linecap="square"

  146. stroke-width="8"

  147. fill="none">

  148. <path class="dot dot-1" d="M28,48 l8,0z" />

  149. <path class="dot dot-2" d="M-4,48 l8,0z" />

  150. <path class="dot dot-3" d="M4,16 l8,0z" />

  151. <path class="snake"

  152. d="M0 16 h48 v16 H32 v32 H0 V48 h16 V0 H0 v16"/>

  153. </g>

  154. <rect x="-4.5" y="-4.5" width="57" height="73" fill="url(#pattern)"></rect>

  155. </svg>

  156. </div>

  157. </body>

  158. </html>

感謝  ·  轉發歡迎大家留言

640?wx_fmt=jpeg