当前位置:   article > 正文

在圣诞及元旦的日子里如何用html代码画一个爱心树_html网页表白爱心树

html网页表白爱心树

一、前言

圣诞节以及元旦节日来临的日子里,如果能亲自为自己所爱的人画一个爱心树,这肯定是个很浪漫的事。那么如何用代码画出圣诞树呢?用我的办法就能很简单的实现,复制-粘贴-另存就可完成。

二、创意名

绚丽多彩的爱心树

三、效果展示

四、实现步骤

一:将html的代码复制

具体见后面的代码

二:打开UltraEdit记事本,将代码复制到记事本中

三、另存为love.html

四、用浏览器打开love.html

五、编码实现

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>爱心树表白动画</title>
  6. <style>
  7. body {
  8. margin: 0;
  9. padding: 0;
  10. background: #fafafa;
  11. font-size: 14px;
  12. font-family: "微软雅黑", "宋体", sans-serif;
  13. color: #231f20;
  14. overflow: auto;
  15. }
  16. a {
  17. color: #000;
  18. font-size: 14px;
  19. }
  20. #main {
  21. width: 100%;
  22. }
  23. #wrap {
  24. position: relative;
  25. margin: 0 auto;
  26. width: 1100px;
  27. height: 680px;
  28. margin-top: 10px;
  29. }
  30. #text {
  31. width: 400px;
  32. height: 425px;
  33. left: 60px;
  34. top: 80px;
  35. position: absolute;
  36. }
  37. #code {
  38. display: none;
  39. font-size: 16px;
  40. }
  41. #clock-box {
  42. position: absolute;
  43. left: 60px;
  44. top: 550px;
  45. font-size: 28px;
  46. display: none;
  47. }
  48. #clock-box a {
  49. font-size: 28px;
  50. text-decoration: none;
  51. }
  52. #clock {
  53. margin-left: 48px;
  54. }
  55. #clock .digit {
  56. font-size: 64px;
  57. }
  58. #canvas {
  59. margin: 0 auto;
  60. width: 1100px;
  61. height: 680px;
  62. }
  63. #error {
  64. margin: 0 auto;
  65. text-align: center;
  66. margin-top: 60px;
  67. display: none;
  68. }
  69. .hand {
  70. cursor: pointer;
  71. }
  72. .say {
  73. margin-left: 5px;
  74. }
  75. .space {
  76. margin-right: 150px;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <div id="main">
  82. <div id="error">
  83. 抱歉!目前您的浏览器无法显示,请更新至最新版本或使用其他主流浏览器,谢谢合作。
  84. </div>
  85. <div id="wrap">
  86. <canvas id="canvas" width="1100" height="680"></canvas>
  87. </div>
  88. </div>
  89. <script
  90. type="text/javascript"
  91. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jquery.min.js"
  92. ></script>
  93. <script
  94. type="text/javascript"
  95. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex.min.js"
  96. ></script>
  97. <script
  98. type="text/javascript"
  99. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex-parser.js"
  100. ></script>
  101. <script
  102. type="text/javascript"
  103. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex-jit.js"
  104. ></script>
  105. <script
  106. type="text/javascript"
  107. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex-builderbase.min.js"
  108. ></script>
  109. <script
  110. type="text/javascript"
  111. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex-async.min.js"
  112. ></script>
  113. <script
  114. type="text/javascript"
  115. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/jscex-async-powerpack.min.js"
  116. ></script>
  117. <script
  118. type="text/javascript"
  119. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/functions.js"
  120. charset="utf-8"
  121. ></script>
  122. <script
  123. type="text/javascript"
  124. src="https://cdn-static-devbit.csdn.net/devbit-static/code/love-tree/js/love.js"
  125. charset="utf-8"
  126. ></script>
  127. <script>
  128. (function () {
  129. var canvas = $("#canvas");
  130. if (!canvas[0].getContext) {
  131. $("#error").show();
  132. return false;
  133. }
  134. var width = canvas.width();
  135. var height = canvas.height();
  136. canvas.attr("width", width);
  137. canvas.attr("height", height);
  138. var opts = {
  139. seed: {
  140. x: width / 2 - 20,
  141. color: "rgb(190, 26, 37)",
  142. scale: 2
  143. },
  144. branch: [
  145. [
  146. 535,
  147. 680,
  148. 570,
  149. 250,
  150. 500,
  151. 200,
  152. 30,
  153. 100,
  154. [
  155. [
  156. 540,
  157. 500,
  158. 455,
  159. 417,
  160. 340,
  161. 400,
  162. 13,
  163. 100,
  164. [[450, 435, 434, 430, 394, 395, 2, 40]]
  165. ],
  166. [
  167. 550,
  168. 445,
  169. 600,
  170. 356,
  171. 680,
  172. 345,
  173. 12,
  174. 100,
  175. [[578, 400, 648, 409, 661, 426, 3, 80]]
  176. ],
  177. [539, 281, 537, 248, 534, 217, 3, 40],
  178. [
  179. 546,
  180. 397,
  181. 413,
  182. 247,
  183. 328,
  184. 244,
  185. 9,
  186. 80,
  187. [
  188. [427, 286, 383, 253, 371, 205, 2, 40],
  189. [498, 345, 435, 315, 395, 330, 4, 60]
  190. ]
  191. ],
  192. [
  193. 546,
  194. 357,
  195. 608,
  196. 252,
  197. 678,
  198. 221,
  199. 6,
  200. 100,
  201. [[590, 293, 646, 277, 648, 271, 2, 80]]
  202. ]
  203. ]
  204. ]
  205. ],
  206. bloom: {
  207. num: 700,
  208. width: 1080,
  209. height: 650
  210. },
  211. footer: {
  212. width: 1200,
  213. height: 5,
  214. speed: 10
  215. }
  216. };
  217. var tree = new Tree(canvas[0], width, height, opts);
  218. var seed = tree.seed;
  219. var foot = tree.footer;
  220. var hold = 1;
  221. canvas
  222. .click(function (e) {
  223. var offset = canvas.offset(),
  224. x,
  225. y;
  226. x = e.pageX - offset.left;
  227. y = e.pageY - offset.top;
  228. if (seed.hover(x, y)) {
  229. hold = 0;
  230. canvas.unbind("click");
  231. canvas.unbind("mousemove");
  232. canvas.removeClass("hand");
  233. }
  234. })
  235. .mousemove(function (e) {
  236. var offset = canvas.offset(),
  237. x,
  238. y;
  239. x = e.pageX - offset.left;
  240. y = e.pageY - offset.top;
  241. canvas.toggleClass("hand", seed.hover(x, y));
  242. });
  243. var seedAnimate = eval(
  244. Jscex.compile("async", function () {
  245. seed.draw();
  246. while (hold) {
  247. $await(Jscex.Async.sleep(10));
  248. }
  249. while (seed.canScale()) {
  250. seed.scale(0.95);
  251. $await(Jscex.Async.sleep(10));
  252. }
  253. while (seed.canMove()) {
  254. seed.move(0, 2);
  255. foot.draw();
  256. $await(Jscex.Async.sleep(10));
  257. }
  258. })
  259. );
  260. var growAnimate = eval(
  261. Jscex.compile("async", function () {
  262. do {
  263. tree.grow();
  264. $await(Jscex.Async.sleep(10));
  265. } while (tree.canGrow());
  266. })
  267. );
  268. var flowAnimate = eval(
  269. Jscex.compile("async", function () {
  270. do {
  271. tree.flower(2);
  272. $await(Jscex.Async.sleep(10));
  273. } while (tree.canFlower());
  274. })
  275. );
  276. var moveAnimate = eval(
  277. Jscex.compile("async", function () {
  278. tree.snapshot("p1", 240, 0, 610, 680);
  279. canvas
  280. .parent()
  281. .css("background", "url(" + tree.toDataURL("image/png") + ")");
  282. canvas.css("background", "#fafafa");
  283. $await(Jscex.Async.sleep(300));
  284. canvas.css("background", "none");
  285. })
  286. );
  287. var jumpAnimate = eval(
  288. Jscex.compile("async", function () {
  289. var ctx = tree.ctx;
  290. while (true) {
  291. tree.ctx.clearRect(0, 0, width, height);
  292. tree.jump();
  293. foot.draw();
  294. $await(Jscex.Async.sleep(25));
  295. }
  296. })
  297. );
  298. var textAnimate = eval(
  299. Jscex.compile("async", function () {
  300. var together = new Date();
  301. together.setFullYear(2010, 1, 15); //时间年月日
  302. together.setHours(16); //小时
  303. together.setMinutes(53); //分钟
  304. together.setSeconds(0); //秒前一位
  305. together.setMilliseconds(2); //秒第二位
  306. $("#code").show().typewriter();
  307. $("#clock-box").fadeIn(500);
  308. while (true) {
  309. timeElapse(together);
  310. $await(Jscex.Async.sleep(1000));
  311. }
  312. })
  313. );
  314. var runAsync = eval(
  315. Jscex.compile("async", function () {
  316. $await(seedAnimate());
  317. $await(growAnimate());
  318. $await(flowAnimate());
  319. $await(moveAnimate());
  320. $await(jumpAnimate());
  321. })
  322. );
  323. runAsync().start();
  324. })();
  325. </script>
  326. </body>
  327. </html>

提醒:在发布作品前请把不用的内容删掉

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/120664
推荐阅读
相关标签
  

闽ICP备14008679号