当前位置:   article > 正文

html动态爱心代码【附源码】_爱心代码html源码

爱心代码html源码

来,大家先看图片(时间都是会动的)

是不是很美啊

话不多说,上代码

顺计时

  1. <head>
  2. <meta charset="utf-8">
  3. <title>快乐</title>
  4. <style>
  5. body {
  6. overflow: hidden;
  7. margin: 0;
  8. }
  9. h1 {
  10. position: fixed;
  11. top: 30%;
  12. left: 0;
  13. width: 100%;
  14. text-align: center;
  15. transform: translateY(-50%);
  16. font-family: 'Love Ya Like A Sister', cursive;
  17. font-size: 60px;
  18. color: ff64d9;
  19. padding: 0 20px;
  20. }
  21. h1 span {
  22. position: fixed;
  23. left: 0;
  24. width: 100%;
  25. text-align: center;
  26. margin-top: 30px;
  27. font-size: 40px;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <h1 id="h1"></h1>
  33. <canvas></canvas>
  34. <script>
  35. var canvas = document.querySelector("canvas"),
  36. ctx = canvas.getContext("2d");
  37. var ww, wh;
  38. function onResize() {
  39. ww = canvas.width = window.innerWidth;
  40. wh = canvas.height = window.innerHeight;
  41. }
  42. ctx.strokeStyle = "red";
  43. ctx.shadowBlur = 25;
  44. ctx.shadowColor = "hsla(0, 100%, 60%,0.5)";
  45. var precision = 100;
  46. var hearts = [];
  47. var mouseMoved = false;
  48. function onMove(e) {
  49. mouseMoved = true;
  50. if (e.type === "tm") {
  51. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  52. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  53. } else {
  54. hearts.push(new Heart(e.clientX, e.clientY));
  55. hearts.push(new Heart(e.clientX, e.clientY));
  56. }
  57. }
  58. var Heart = function(x, y) {
  59. this.x = x || Math.random() * ww;
  60. this.y = y || Math.random() * wh;
  61. this.size = Math.random() * 2 + 1;
  62. this.shadowBlur = Math.random() * 10;
  63. this.speedX = (Math.random() + 0.2 - 0.6) * 8;
  64. this.speedY = (Math.random() + 0.2 - 0.6) * 8;
  65. this.speedSize = Math.random() * 0.05 + 0.01;
  66. this.opacity = 1;
  67. this.vertices = [];
  68. for (var i = 0; i < precision; i++) {
  69. var step = (i / precision - 0.5) * (Math.PI * 2);
  70. var vector = {
  71. x: (15 * Math.pow(Math.sin(step), 3)),
  72. y: -(13 * Math.cos(step) - 5 * Math.cos(2 * step) - 2 * Math.cos(3 * step) - Math.cos(4 * step))
  73. }
  74. this.vertices.push(vector);
  75. }
  76. }
  77. Heart.prototype.draw = function() {
  78. this.size -= this.speedSize;
  79. this.x += this.speedX;
  80. this.y += this.speedY;
  81. ctx.save();
  82. ctx.translate(-1000, this.y);
  83. ctx.scale(this.size, this.size);
  84. ctx.beginPath();
  85. for (var i = 0; i < precision; i++) {
  86. var vector = this.vertices[i];
  87. ctx.lineTo(vector.x, vector.y);
  88. }
  89. ctx.globalAlpha = this.size;
  90. ctx.shadowBlur = Math.round((3 - this.size) * 10);
  91. ctx.shadowColor = "hsla(0, 100%, 60%,0.5)";
  92. ctx.shadowOffsetX = this.x + 1000;
  93. ctx.globalCompositeOperation = "screen"
  94. ctx.closePath();
  95. ctx.fill()
  96. ctx.restore();
  97. };
  98. function render(a) {
  99. requestAnimationFrame(render);
  100. hearts.push(new Heart())
  101. ctx.clearRect(0, 0, ww, wh);
  102. for (var i = 0; i < hearts.length; i++) {
  103. hearts[i].draw();
  104. if (hearts[i].size <= 0) {
  105. hearts.splice(i, 1);
  106. i--;
  107. }
  108. }
  109. }
  110. onResize();
  111. window.addEventListener("mmo", onMove);
  112. window.addEventListener("tm", onMove);
  113. window.addEventListener("resize", onResize);
  114. requestAnimationFrame(render);
  115. window.onload = function starttime() {
  116. time(h1, '2023,03,08'); // 2023年女神节时间+1
  117. ptimer = setTimeout(starttime, 1000); // 添加计时器
  118. }
  119. function time(obj, futimg) {
  120. var nowtime = new Date().getTime(); // 现在时间转换为时间戳
  121. var futruetime = new Date(futimg).getTime(); // 未来时间转换为时间戳
  122. var msec = nowtime - futruetime; // 毫秒 现在时间-未来时间
  123. var time = (msec / 1000); // 毫秒/1000
  124. var day = parseInt(time / 86400); // 天 24*60*60*1000
  125. var hour = parseInt(time / 3600) - 24 * day; // 小时 60*60 总小时数-过去的小时数=现在的小时数
  126. var minute = parseInt(time % 3600 / 60); // 分 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
  127. var second = parseInt(time % 60); // 以60秒为一整份 取余 剩下秒数
  128. var mz = second<10?'0'+second:second;
  129. var fz = minute<10?'0'+minute:minute;
  130. obj.innerHTML = "<b><br>每天快乐:<br></b>" + hour + ":" + fz + ":" + mz +
  131. "<br><span>愿东哥<br>平安喜乐<br>万事顺遂</span>"
  132. return true;
  133. }
  134. </script>
  135. </body>

 倒计时

  1. <head>
  2. <meta charset="utf-8">
  3. <title>未来</title>
  4. <style>
  5. body {
  6. overflow: hidden;
  7. margin: 0;
  8. }
  9. h1 {
  10. position: fixed;
  11. top: 30%;
  12. left: 0;
  13. width: 100%;
  14. text-align: center;
  15. transform: translateY(-50%);
  16. font-family: 'Love Ya Like A Sister', cursive;
  17. font-size: 60px;
  18. color: ff64d9;
  19. padding: 0 20px;
  20. }
  21. h1 span {
  22. position: fixed;
  23. left: 0;
  24. width: 100%;
  25. text-align: center;
  26. margin-top: 30px;
  27. font-size: 40px;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <h1 id="h1"></h1>
  33. <canvas></canvas>
  34. <script>
  35. var canvas = document.querySelector("canvas"),
  36. ctx = canvas.getContext("2d");
  37. var ww, wh;
  38. function onResize() {
  39. ww = canvas.width = window.innerWidth;
  40. wh = canvas.height = window.innerHeight;
  41. }
  42. ctx.strokeStyle = "red";
  43. ctx.shadowBlur = 25;
  44. ctx.shadowColor = "hsla(0, 100%, 60%,0.5)";
  45. var precision = 100;
  46. var hearts = [];
  47. var mouseMoved = false;
  48. function onMove(e) {
  49. mouseMoved = true;
  50. if (e.type === "touchmove") {
  51. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  52. hearts.push(new Heart(e.touches[0].clientX, e.touches[0].clientY));
  53. } else {
  54. hearts.push(new Heart(e.clientX, e.clientY));
  55. hearts.push(new Heart(e.clientX, e.clientY));
  56. }
  57. }
  58. var Heart = function(x, y) {
  59. this.x = x || Math.random() * ww;
  60. this.y = y || Math.random() * wh;
  61. this.size = Math.random() * 2 + 1;
  62. this.shadowBlur = Math.random() * 10;
  63. this.speedX = (Math.random() + 0.2 - 0.6) * 8;
  64. this.speedY = (Math.random() + 0.2 - 0.6) * 8;
  65. this.speedSize = Math.random() * 0.05 + 0.01;
  66. this.opacity = 1;
  67. this.vertices = [];
  68. for (var i = 0; i < precision; i++) {
  69. var step = (i / precision - 0.5) * (Math.PI * 2);
  70. var vector = {
  71. x: (15 * Math.pow(Math.sin(step), 3)),
  72. y: -(13 * Math.cos(step) - 5 * Math.cos(2 * step) - 2 * Math.cos(3 * step) - Math.cos(4 * step))
  73. }
  74. this.vertices.push(vector);
  75. }
  76. }
  77. Heart.prototype.draw = function() {
  78. this.size -= this.speedSize;
  79. this.x += this.speedX;
  80. this.y += this.speedY;
  81. ctx.save();
  82. ctx.translate(-1000, this.y);
  83. ctx.scale(this.size, this.size);
  84. ctx.beginPath();
  85. for (var i = 0; i < precision; i++) {
  86. var vector = this.vertices[i];
  87. ctx.lineTo(vector.x, vector.y);
  88. }
  89. ctx.globalAlpha = this.size;
  90. ctx.shadowBlur = Math.round((3 - this.size) * 10);
  91. ctx.shadowColor = "hsla(140, 66%, 66%, 255)";
  92. ctx.shadowOffsetX = this.x + 1000;
  93. ctx.globalCompositeOperation = "screen"
  94. ctx.closePath();
  95. ctx.fill()
  96. ctx.restore();
  97. };
  98. function render(a) {
  99. requestAnimationFrame(render);
  100. hearts.push(new Heart())
  101. ctx.clearRect(0, 0, ww, wh);
  102. for (var i = 0; i < hearts.length; i++) {
  103. hearts[i].draw();
  104. if (hearts[i].size <= 0) {
  105. hearts.splice(i, 1);
  106. i--;
  107. }
  108. }
  109. }
  110. onResize();
  111. window.addEventListener("mousemove", onMove);
  112. window.addEventListener("touchmove", onMove);
  113. window.addEventListener("resize", onResize);
  114. requestAnimationFrame(render);
  115. window.onload = function starttime() {
  116. time(h1, '2024,1,1'); // 2023年1月1日
  117. ptimer = setTimeout(starttime, 1000); // 添加计时器
  118. }
  119. function time(obj, futimg) {
  120. var nowtime = new Date().getTime(); // 现在时间转换为时间戳
  121. var futruetime = new Date(futimg).getTime(); // 未来时间转换为时间戳
  122. var msec = futruetime - nowtime; // 毫秒 未来时间-现在时间
  123. var time = (msec / 1000); // 毫秒/1000
  124. var day = parseInt(time / 86400); // 天 24*60*60*1000
  125. var hour = parseInt(time / 3600) - 24 * day; // 小时 60*60 总小时数-过去的小时数=现在的小时数
  126. var minute = parseInt(time % 3600 / 60); // 分 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
  127. var second = parseInt(time % 60); // 以60秒为一整份 取余 剩下秒数
  128. obj.innerHTML = "<br>距2024年还有:<br>" + day + "天" + hour + "小时" + minute + "分" + second + "秒" +
  129. "<br><span>愿在明年来临前<br>大家将迎来新的蜕变</span>"
  130. return true;
  131. }
  132. </script>
  133. </body>

祝大家在情场顺风顺水 !!

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

闽ICP备14008679号