当前位置:   article > 正文

2023年兔年快乐HTML代码制作_新年祝福的html

新年祝福的html

提前祝大家兔年快乐!

 

时光荏苒,白驹过隙。
2022这一年又在忙碌中度过了,过去的一年,我们同努力,我们共欢笑,每一次成功都蕴藏着我们辛勤的劳动。
新的一年即将来到,我们不能停滞不前,一味只是骄傲。愿大家与时俱进,拼搏不懈,共创新的辉煌!
借着新年到来的喜庆,给大家分享一个新年烟花的前端代码,快拿着代码展示给你的朋友们看吧!!
转眼间已经到了2022的尾巴,这一年对于国家来说丰富充实,冬奥会在北京举行、中国共产党第二十次全国代表大会召开、社会共同抗击疫情的第三年、我国完成天宫空间站建造……对于我们每一个个体,2022也承载着我们的快乐与悲伤,它是无法替代的。
新的一年马上就要到了,让我们告别2022,迎接2023!
希望2023,全糖去冰。
 

上代码

效果展示:

 HTML源码:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  5. <style>
  6. body {
  7. margin: 0;
  8. padding: 0;
  9. overflow: hidden;
  10. }
  11. .city {
  12. width: 100%;
  13. position: fixed;
  14. bottom: 0px;
  15. z-index: 100;
  16. }
  17. .city img {
  18. width: 100%;
  19. }
  20. </style>
  21. <title>2023兔年快乐</title>
  22. </head>
  23. <body onselectstart="return false">
  24. <canvas id='cas' style="background-color:rgba(0,5,24,1)">浏览器不支持canvas</canvas>
  25. <div class="city"><img src="city.png" alt=""/></div>
  26. <img src="moon.png" alt="" id="moon" style="visibility: hidden;"/>
  27. <div style="display:none">
  28. <div class="shape">2023新年快乐</div>
  29. <div class="shape">兔年大吉</div>
  30. <div class="shape">万事如意</div>
  31. <div class="shape">恭喜发财</div>
  32. </div>
  33. <audio src="boom.mp3" preload="auto"></audio>
  34. <audio src="boom.mp3" preload="auto"></audio>
  35. <audio src="boom.mp3" preload="auto"></audio>
  36. <audio src="boom.mp3" preload="auto"></audio>
  37. <audio src="boom.mp3" preload="auto"></audio>
  38. <audio src="boom.mp3" preload="auto"></audio>
  39. <audio src="shotfire.mp3" preload="auto"></audio>
  40. <audio src="shotfire.mp3" preload="auto"></audio>
  41. <audio src="shotfire.mp3" preload="auto"></audio>
  42. <script>
  43. var canvas = document.getElementById("cas");
  44. var ocas = document.createElement("canvas");
  45. var octx = ocas.getContext("2d");
  46. var ctx = canvas.getContext("2d");
  47. ocas.width = canvas.width = window.innerWidth;
  48. ocas.height = canvas.height = window.innerHeight;
  49. var bigbooms = [];
  50. window.onload = function() {
  51. initAnimate()
  52. }
  53. function initAnimate() {
  54. drawBg();
  55. lastTime = new Date();
  56. animate();
  57. }
  58. var lastTime;
  59. function animate() {
  60. ctx.save();
  61. ctx.globalCompositeOperation = 'destination-out';
  62. ctx.globalAlpha = 0.1;
  63. ctx.fillRect(0, 0, canvas.width, canvas.height);
  64. ctx.restore();
  65. var newTime = new Date();
  66. if (newTime - lastTime > 200 + (window.innerHeight - 767) / 2) {
  67. var random = Math.random() * 100 > 2 ? true : false;
  68. var x = getRandom(canvas.width / 5, canvas.width * 4 / 5);
  69. var y = getRandom(50, 200);
  70. if (random) {
  71. var bigboom = new Boom(getRandom(canvas.width / 3, canvas.width * 2 / 3), 2, "#FFF", {x: x, y: y});
  72. bigbooms.push(bigboom)
  73. }
  74. else {
  75. var bigboom = new Boom(getRandom(canvas.width / 3, canvas.width * 2 / 3), 2, "#FFF", {
  76. x: canvas.width / 2,
  77. y: 200
  78. }, document.querySelectorAll(".shape")[parseInt(getRandom(0, document.querySelectorAll(".shape").length))]);
  79. bigbooms.push(bigboom)
  80. }
  81. lastTime = newTime;
  82. }
  83. stars.foreach(function() {
  84. this.paint();
  85. })
  86. drawMoon();
  87. bigbooms.foreach(function(index) {
  88. var that = this;
  89. if (!this.dead) {
  90. this._move();
  91. this._drawLight();
  92. }
  93. else {
  94. this.booms.foreach(function(index) {
  95. if (!this.dead) {
  96. this.moveTo(index);
  97. }
  98. else if (index === that.booms.length - 1) {
  99. bigbooms.splice(bigbooms.indexOf(that), 1);
  100. }
  101. })
  102. }
  103. });
  104. raf(animate);
  105. }
  106. function drawMoon() {
  107. var moon = document.getElementById("moon");
  108. var centerX = canvas.width - 200, centerY = 100, width = 80;
  109. if (moon.complete) {
  110. ctx.drawImage(moon, centerX, centerY, width, width)
  111. }
  112. else {
  113. moon.onload = function() {
  114. ctx.drawImage(moon, centerX, centerY, width, width)
  115. }
  116. }
  117. var index = 0;
  118. for (var i = 0; i < 10; i++) {
  119. ctx.save();
  120. ctx.beginPath();
  121. ctx.arc(centerX + width / 2, centerY + width / 2, width / 2 + index, 0, 2 * Math.PI);
  122. ctx.fillStyle = "rgba(240,219,120,0.005)";
  123. index += 2;
  124. ctx.fill();
  125. ctx.restore();
  126. }
  127. }
  128. Array.prototype.foreach = function(callback) {
  129. for (var i = 0; i < this.length; i++) {
  130. if (this[i] !== null) callback.apply(this[i], [i])
  131. }
  132. }
  133. var raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
  134. window.setTimeout(callback, 1000 / 10);
  135. };
  136. canvas.onclick = function() {
  137. var x = event.clientX;
  138. var y = event.clientY;
  139. var bigboom = new Boom(getRandom(canvas.width / 3, canvas.width * 2 / 3), 2, "#FFF", {x: x, y: y});
  140. bigbooms.push(bigboom)
  141. }
  142. var Boom = function(x, r, c, boomArea, shape) {
  143. this.booms = [];
  144. this.x = x;
  145. this.y = (canvas.height + r);
  146. this.r = r;
  147. this.c = c;
  148. this.shape = shape || false;
  149. this.boomArea = boomArea;
  150. this.theta = 0;
  151. this.dead = false;
  152. this.ba = parseInt(getRandom(80, 200));
  153. var audio = document.getElementsByTagName("audio");
  154. for (var i = 0; i < audio.length; i++) {
  155. if (audio[i].src.indexOf("shotfire") >= 0 && (audio[i].paused || audio[i].ended)) {
  156. audio[i].play();
  157. break;
  158. }
  159. }
  160. }
  161. Boom.prototype = {
  162. _paint: function() {
  163. ctx.save();
  164. ctx.beginPath();
  165. ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI);
  166. ctx.fillStyle = this.c;
  167. ctx.fill();
  168. ctx.restore();
  169. },
  170. _move: function() {
  171. var dx = this.boomArea.x - this.x, dy = this.boomArea.y - this.y;
  172. this.x = this.x + dx * 0.01;
  173. this.y = this.y + dy * 0.01;
  174. if (Math.abs(dx) <= this.ba && Math.abs(dy) <= this.ba) {
  175. if (this.shape) {
  176. this._shapBoom();
  177. }
  178. else this._boom();
  179. this.dead = true;
  180. }
  181. else {
  182. this._paint();
  183. }
  184. },
  185. _drawLight: function() {
  186. ctx.save();
  187. ctx.fillStyle = "rgba(255,228,150,0.3)";
  188. ctx.beginPath();
  189. ctx.arc(this.x, this.y, this.r + 3 * Math.random() + 1, 0, 2 * Math.PI);
  190. ctx.fill();
  191. ctx.restore();
  192. },
  193. _boom: function() {
  194. var fragNum = getRandom(100, 300);
  195. var style = getRandom(0, 10) >= 5 ? 1 : 2;
  196. var color;
  197. if (style === 1) {
  198. color = {
  199. a: parseInt(getRandom(128, 255)),
  200. b: parseInt(getRandom(128, 255)),
  201. c: parseInt(getRandom(128, 255))
  202. }
  203. }
  204. var fanwei = fragNum;
  205. var audio = document.getElementsByTagName("audio");
  206. for (var i = 0; i < audio.length; i++) {
  207. if (audio[i].src.indexOf("boom") >= 0 && (audio[i].paused || audio[i].ended)) {
  208. audio[i].play();
  209. break;
  210. }
  211. }
  212. for (var i = 0; i < fragNum; i++) {
  213. if (style === 2) {
  214. color = {
  215. a: parseInt(getRandom(128, 255)),
  216. b: parseInt(getRandom(128, 255)),
  217. c: parseInt(getRandom(128, 255))
  218. }
  219. }
  220. var a = getRandom(-Math.PI, Math.PI);
  221. var x = getRandom(0, fanwei) * Math.cos(a) + this.x;
  222. var y = getRandom(0, fanwei) * Math.sin(a) + this.y;
  223. var radius = getRandom(0, 2)
  224. var frag = new Frag(this.x, this.y, radius, color, x, y);
  225. this.booms.push(frag);
  226. }
  227. },
  228. _shapBoom: function() {
  229. var that = this;
  230. putValue(ocas, octx, this.shape, 5, function(dots) {
  231. var dx = canvas.width / 2 - that.x;
  232. var dy = canvas.height / 2 - that.y;
  233. for (var i = 0; i < dots.length; i++) {
  234. color = {a: dots[i].a, b: dots[i].b, c: dots[i].c}
  235. var x = dots[i].x;
  236. var y = dots[i].y;
  237. var radius = 1;
  238. var frag = new Frag(that.x, that.y, radius, color, x - dx, y - dy);
  239. that.booms.push(frag);
  240. }
  241. })
  242. }
  243. }
  244. function putValue(canvas, context, ele, dr, callback) {
  245. context.clearRect(0, 0, canvas.width, canvas.height);
  246. var img = new Image();
  247. if (ele.innerHTML.indexOf("img") >= 0) {
  248. img.src = ele.getElementsByTagName("img")[0].src;
  249. imgload(img, function() {
  250. context.drawImage(img, canvas.width / 2 - img.width / 2, canvas.height / 2 - img.width / 2);
  251. dots = getimgData(canvas, context, dr);
  252. callback(dots);
  253. })
  254. }
  255. else {
  256. var text = ele.innerHTML;
  257. context.save();
  258. var fontSize = 200;
  259. context.font = fontSize + "px 宋体 bold";
  260. context.textAlign = "center";
  261. context.textBaseline = "middle";
  262. context.fillStyle = "rgba(" + parseInt(getRandom(128, 255)) + "," + parseInt(getRandom(128, 255)) + "," + parseInt(getRandom(128, 255)) + " , 1)";
  263. context.fillText(text, canvas.width / 2, canvas.height / 2);
  264. context.restore();
  265. dots = getimgData(canvas, context, dr);
  266. callback(dots);
  267. }
  268. }
  269. function imgload(img, callback) {
  270. if (img.complete) {
  271. callback.call(img);
  272. }
  273. else {
  274. img.onload = function() {
  275. callback.call(this);
  276. }
  277. }
  278. }
  279. function getimgData(canvas, context, dr) {
  280. var imgData = context.getImageData(0, 0, canvas.width, canvas.height);
  281. context.clearRect(0, 0, canvas.width, canvas.height);
  282. var dots = [];
  283. for (var x = 0; x < imgData.width; x += dr) {
  284. for (var y = 0; y < imgData.height; y += dr) {
  285. var i = (y * imgData.width + x) * 4;
  286. if (imgData.data[i + 3] > 128) {
  287. var dot = {x: x, y: y, a: imgData.data[i], b: imgData.data[i + 1], c: imgData.data[i + 2]};
  288. dots.push(dot);
  289. }
  290. }
  291. }
  292. return dots;
  293. }
  294. function getRandom(a, b) {
  295. return Math.random() * (b - a) + a;
  296. }
  297. var maxRadius = 1, stars = [];
  298. function drawBg() {
  299. for (var i = 0; i < 100; i++) {
  300. var r = Math.random() * maxRadius;
  301. var x = Math.random() * canvas.width;
  302. var y = Math.random() * 2 * canvas.height - canvas.height;
  303. var star = new Star(x, y, r);
  304. stars.push(star);
  305. star.paint()
  306. }
  307. }
  308. var Star = function(x, y, r) {
  309. this.x = x;
  310. this.y = y;
  311. this.r = r;
  312. }
  313. Star.prototype = {
  314. paint: function() {
  315. ctx.save();
  316. ctx.beginPath();
  317. ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI);
  318. ctx.fillStyle = "rgba(255,255,255," + this.r + ")";
  319. ctx.fill();
  320. ctx.restore();
  321. }
  322. }
  323. var focallength = 250;
  324. var Frag = function(centerX, centerY, radius, color, tx, ty) {
  325. this.tx = tx;
  326. this.ty = ty;
  327. this.x = centerX;
  328. this.y = centerY;
  329. this.dead = false;
  330. this.centerX = centerX;
  331. this.centerY = centerY;
  332. this.radius = radius;
  333. this.color = color;
  334. }
  335. Frag.prototype = {
  336. paint: function() {
  337. // ctx.beginPath();
  338. // ctx.arc(this.x , this.y , this.radius , 0 , 2*Math.PI);
  339. ctx.fillStyle = "rgba(" + this.color.a + "," + this.color.b + "," + this.color.c + ",1)";
  340. ctx.fillRect(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2)
  341. },
  342. moveTo: function(index) {
  343. this.ty = this.ty + 0.3;
  344. var dx = this.tx - this.x, dy = this.ty - this.y;
  345. this.x = Math.abs(dx) < 0.1 ? this.tx : (this.x + dx * 0.1);
  346. this.y = Math.abs(dy) < 0.1 ? this.ty : (this.y + dy * 0.1);
  347. if (dx === 0 && Math.abs(dy) <= 80) {
  348. this.dead = true;
  349. }
  350. this.paint();
  351. }
  352. }
  353. </script>
  354. </body>
  355. </html>

视频展示:

2023兔年快乐HTML代码展示

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

闽ICP备14008679号