当前位置:   article > 正文

2024情人节/除夕/新年快乐+表白,3D粒子动态特效+烟花,可直接运行(附赠源码:文章尾)

2024情人节/除夕/新年快乐+表白,3D粒子动态特效+烟花,可直接运行(附赠源码:文章尾)

马上就要迎接新年了,新的一年祝大家兔管纤纤着重彩,龙行龘龘创未来!!

1.代码效果展示



2.代码展示

  1. var S = {
  2. init: function () {
  3. var action = window.location.href,
  4. i = action.indexOf('?a=');
  5. S.Drawing.init('.canvas');
  6. document.body.classList.add('body--ready');
  7. if (i !== -1) {
  8. S.UI.simulate(decodeURI(action).substring(i + 3));
  9. } else {
  10. S.UI.simulate('|#countdown 4||除|夕|快|乐|阿贵学长|兔管纤纤着重彩|龙行龘龘创未来|2024 HAPPY NEW YEAR');
  11. }
  12. S.Drawing.loop(function () {
  13. S.Shape.render();
  14. });
  15. }
  16. };
  17. S.Drawing = (function () {
  18. var canvas,
  19. context,
  20. renderFn
  21. requestFrame = window.requestAnimationFrame ||
  22. window.webkitRequestAnimationFrame ||
  23. window.mozRequestAnimationFrame ||
  24. window.oRequestAnimationFrame ||
  25. window.msRequestAnimationFrame ||
  26. function(callback) {
  27. window.setTimeout(callback, 1000 / 60);
  28. };
  29. return {
  30. init: function (el) {
  31. canvas = document.querySelector(el);
  32. context = canvas.getContext('2d');
  33. this.adjustCanvas();
  34. window.addEventListener('resize', function (e) {
  35. S.Drawing.adjustCanvas();
  36. });
  37. },
  38. loop: function (fn) {
  39. renderFn = !renderFn ? fn : renderFn;
  40. this.clearFrame();
  41. renderFn();
  42. requestFrame.call(window, this.loop.bind(this));
  43. },
  44. adjustCanvas: function () {
  45. canvas.width = window.innerWidth;
  46. canvas.height = window.innerHeight;
  47. },
  48. clearFrame: function () {
  49. context.clearRect(0, 0, canvas.width, canvas.height);
  50. },
  51. getArea: function () {
  52. return { w: canvas.width, h: canvas.height };
  53. },
  54. drawCircle: function (p, c) {
  55. context.fillStyle = '#e2005d';
  56. context.beginPath();
  57. context.arc(p.x, p.y, p.z, 0, 2 * Math.PI, true);
  58. context.closePath();
  59. context.fill();
  60. }
  61. }
  62. }());
  63. S.UI = (function () {
  64. var canvas = document.querySelector('.canvas'),
  65. interval,
  66. isTouch = false, //('ontouchstart' in window || navigator.msMaxTouchPoints),
  67. currentAction,
  68. resizeTimer,
  69. time,
  70. maxShapeSize = 30,
  71. firstAction = true,
  72. sequence = [],
  73. cmd = '#';
  74. function formatTime(date) {
  75. var h = date.getHours(),
  76. m = date.getMinutes(),
  77. m = m < 10 ? '0' + m : m;
  78. return h + ':' + m;
  79. }
  80. function getValue(value) {
  81. return value && value.split(' ')[1];
  82. }
  83. function getAction(value) {
  84. value = value && value.split(' ')[0];
  85. return value && value[0] === cmd && value.substring(1);
  86. }
  87. function timedAction(fn, delay, max, reverse) {
  88. clearInterval(interval);
  89. currentAction = reverse ? max : 1;
  90. fn(currentAction);
  91. if (!max || (!reverse && currentAction < max) || (reverse && currentAction > 0)) {
  92. interval = setInterval(function () {
  93. currentAction = reverse ? currentAction - 1 : currentAction + 1;
  94. fn(currentAction);
  95. if ((!reverse && max && currentAction === max) || (reverse && currentAction === 0)) {
  96. clearInterval(interval);
  97. }
  98. }, delay);
  99. }
  100. }
  101. function reset(destroy) {
  102. clearInterval(interval);
  103. sequence = [];
  104. time = null;
  105. destroy && S.Shape.switchShape(S.ShapeBuilder.letter(''));
  106. }
  107. function performAction(value) {
  108. var action,
  109. value,
  110. current;
  111. // overlay.classList.remove('overlay--visible');
  112. sequence = typeof(value) === 'object' ? value : sequence.concat(value.split('|'));
  113. // input.value = '';
  114. // checkInputWidth();

3.源码

2024除夕/新年快乐,3D粒子动态特效,HTML,js实现

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

闽ICP备14008679号