当前位置:   article > 正文

HTML实现烟花,鼠标点击爆炸,免费提供源码,复制就可运行_html鼠标点击特效代码

html鼠标点击特效代码

最简单HTML烟花效果图

 

HTML实现代码展示

 

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>CodePen - Happy New Year!</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
  8. <link rel="stylesheet" href="./style.css">
  9. </head>
  10. <body>
  11. <!-- partial:index.partial.html -->
  12. <h1 id="title">Happy New Year!</h1>
  13. <div class="stars"></div>
  14. <svg class="mountains mountains--layer1" xmlns="http://www.w3.org/2000/svg" width="1920" height="200"
  15. viewBox="0 0 1920 200" preserveAspectRatio="none">
  16. <title>bergskedja</title>
  17. <path
  18. d="M0,41.57s21.25,2.19,27.33,2.19,22.27-4.37,28.34,0-1,22.94,6.07,19.67S72.87,52,81,52.81s16.19,10.15,22.27,0,25.3-1.41,30.36,6.24,21.25,7.33,26.32,4.76,8.1-20.66,16.19-22,17.21-6.31,18.22,0,5.06,3,12.15,3,20.24-10.93,25.3-14.2S238.86,11,259.1,11s35.42,4.37,43.52,0S316.79.05,321.86.05,337-1,337,6.61s6.07,24.92,15.18,26.12,30.36,11,34.41,14.31,18.22-2.19,18.22-2.19c11.13,7.65,20.24,0,20.24,0S441.29,23,453.43,18.63s17.21,4.37,20.24,7.65S497,32.62,500,32.73s19.23-10.82,23.28-10.82,27.33-4.37,34.41-3.28,16.19,10.72,16.19,14.1S582,52.5,586,52.5s15.18,2.19,21.25,2.19,14.17,1.09,17.21,1.09,6.07-3.28,26.32-13.11S669,21.91,677.11,24.09s9.11,14.2,16.19,13.11,0-17.48,24.29-17.48a140.45,140.45,0,0,1,44.53,7.65s3,29.5,17.21,29.5c0,0,28.34-7.65,36.44-7.65s39.47,7.33,47.57,16.23,32.39,12.18,42.51,12.18,25.3,15.3,28.34,15.3,23.28,3.28,28.34-5.46S967.59,66.7,975.69,58s10.12-21.3,17.21-11.2,13.16,8.47,16.19,0,14.17-16.12,17.21-16.12,19.23,3.28,19.23,6.56,25.3-2.19,35.42-12,39.47-9.83,65.79-9.83,54.65,9.83,61.74,14.2,33.4,7.65,42.51,7.65,20.24,4.37,26.32,4.37,5.06,9.83,17.21,13.11,25.3-8.19,28.34-7.92,10.12-16.12,19.23-16.12,27.33,16.94,34.41,16.12,22.27,22.12,28.34,24.31,2,12.13,18.22,22.45,22.27,32.18,34.41,32.18,50.61-8.74,54.65-15.3,22.27-19.67,27.33-19.67,34.41-7.65,38.46-4.37,29.35,22.94,48.58,22.94,46.56-14.2,54.65-14.2,23.28-9.83,35.42-9.83,46.56,12,57.69,14.2,42.51,8.74,58.7,8.74,38.67-42.77,66.8-45.89c6.12-.68,20.24,1.09,20.24,1.09V200H0Z" />
  19. </svg>
  20. <svg class="mountains mountains--layer2" xmlns="http://www.w3.org/2000/svg" width="1920" height="200"
  21. viewBox="0 0 1920 200" preserveAspectRatio="none">
  22. <title>bergskedja2</title>
  23. <path
  24. d="M0,82.09s21.14-13,30.14-19,24-16,45-17.5,49.5-23.86,63-17c0,0,62.87.71,70.5,6.67s81,40.83,127.49,40.83,88.5-20.16,126-24.33,68.23-29.63,90-24.33,31.5,3.89,46.5-.72,25.5-19.61,42-19.61,25.5-7.1,51-7.1,39,11.59,63,11.59,60-3,75,3S864.1,4,882.09,4,934.41,22.09,960,17.59s58.59-7.5,75.09-4.5,36,16.9,61.5,25,82.5,17,97.5,18.55,51.77-6,67.5-10.5S1313,30,1330.81,38s23.76,44,44.76,44,45-6,57-12,31.5-22.5,45-22.5,12,7.5,31.5,7.5,42-4.5,57-4.5,24-25.5,49.5-22.5,66,1.9,90,13,49.5,30.55,78,33.55,54-16.5,69-12,44.91,19.5,67.45,19.5V200H0Z" />
  25. </svg>
  26. <!-- partial -->
  27. <script src='https://cdn.jsdelivr.net/mojs/latest/mo.min.js'></script>
  28. <script src="./script.js"></script>
  29. </body>
  30. </html>

CSS代码展示

  1. @import url("https://fonts.googleapis.com/css?family=Caveat");
  2. html, body {
  3. background: linear-gradient(to bottom, #090513 0%, #964987 75%, #fdbca3 100%);
  4. height: 100%;
  5. display: flex;
  6. align-items: center;
  7. justify-content: center;
  8. overflow: hidden;
  9. }
  10. .stars {
  11. position: absolute;
  12. top: 0;
  13. right: 0;
  14. bottom: 0;
  15. left: 0;
  16. -webkit-animation: rotation 360s infinite linear;
  17. animation: rotation 360s infinite linear;
  18. }
  19. .stars:after, .stars:before {
  20. content: "";
  21. display: block;
  22. position: absolute;
  23. top: 0;
  24. left: 0;
  25. bottom: 0;
  26. right: 0;
  27. background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQAQMAAAC6caSPAAAABlBMVEVHcEz///+flKJDAAAAAXRSTlMAQObYZgAAAIVJREFUeAHt2SEOwkAQhtFJKuqKRRGOgKzgUMgKRI/G0ZDoacNkN/ue/zJ+/ugBcI+01/EEAGBc04FkP58AVFoi7VaSLAEAAPB/j0hbK678AADMkXbZG03mGA0AAKsP3JgAAGDa88knsuZ8Mp1M6gEAPFtNrtEjtkh7lyRb3/PAWpS0BPgC0PMMdOEjXqoAAAAASUVORK5CYII=");
  28. }
  29. .stars:after {
  30. background-size: 100px;
  31. opacity: 0.4;
  32. }
  33. .stars:before {
  34. background-size: 200px;
  35. opacity: 0.6;
  36. }
  37. @-webkit-keyframes rotation {
  38. 0% {
  39. transform: rotate(0);
  40. }
  41. 100% {
  42. transform: rotate(360deg);
  43. }
  44. }
  45. @keyframes rotation {
  46. 0% {
  47. transform: rotate(0);
  48. }
  49. 100% {
  50. transform: rotate(360deg);
  51. }
  52. }
  53. h1 {
  54. font-size: calc(1.5em + 5vw);
  55. color: #fff;
  56. font-family: "Caveat", sans-serif;
  57. text-align: center;
  58. padding: 0.5em;
  59. transform: rotate(-4deg) translateY(-15vh);
  60. }
  61. .mountains {
  62. position: absolute;
  63. bottom: 0;
  64. left: 0;
  65. right: 0;
  66. width: auto;
  67. min-width: 100%;
  68. height: 60px;
  69. fill: #000022;
  70. }
  71. .mountains--layer1 {
  72. z-index: 2;
  73. }
  74. .mountains--layer2 {
  75. fill: #9D5189;
  76. z-index: 0;
  77. }

JavaScript代码展示

  1. // Create the bursts
  2. const B_CHILD = {
  3. fill: { '#ffffff': '#ef1cec' },
  4. delay: 'rand(300, 359)',
  5. duration: 700,
  6. pathScale: 'rand(0.8, 1)',
  7. isSwirl: true,
  8. swirlSize: 'stagger(-2,2)',
  9. swirlFrequency: 1 };
  10. const B_OPTS = {
  11. count: 'rand(15,20)',
  12. top: '100%',
  13. children: {
  14. ...B_CHILD } };
  15. const burst1 = new mojs.Burst({
  16. ...B_OPTS,
  17. radius: { 0: 'rand(150,170)' },
  18. x: -45,
  19. y: -335 });
  20. const burst1_2 = new mojs.Burst({
  21. ...B_OPTS,
  22. radius: { 0: 'rand(150,170)' },
  23. x: -45,
  24. y: -335,
  25. children: {
  26. ...B_CHILD,
  27. delay: 'rand(260, 350)',
  28. pathScale: 'rand(0.7, 0.8)',
  29. degreeShift: 20 } });
  30. const burst2 = new mojs.Burst({
  31. ...B_OPTS,
  32. radius: { 0: 'rand(100,150)' },
  33. x: 140,
  34. y: -315,
  35. children: {
  36. ...B_CHILD,
  37. fill: { '#ffffff': '#d8ff00' } } });
  38. const burst2_2 = new mojs.Burst({
  39. ...B_OPTS,
  40. radius: { 0: 'rand(100,150)' },
  41. x: 140,
  42. y: -315,
  43. children: {
  44. ...B_CHILD,
  45. fill: { '#ffffff': '#d8ff00' },
  46. delay: 'rand(260, 350)',
  47. pathScale: 'rand(0.7, 0.8)',
  48. degreeShift: 20 } });
  49. // Create interactive burst
  50. const burst_tune = new mojs.Burst({
  51. ...B_OPTS,
  52. radius: { 0: 'rand(100,150)' },
  53. left: 0,
  54. top: 0,
  55. x: 0,
  56. y: 0,
  57. children: {
  58. ...B_CHILD,
  59. delay: 'rand(0, 50)',
  60. fill: { '#ffffff': '#d8ff00' } } });
  61. const burst_tune_2 = new mojs.Burst({
  62. ...B_OPTS,
  63. radius: { 0: 'rand(100,150)' },
  64. left: 0,
  65. top: 0,
  66. children: {
  67. ...B_CHILD,
  68. fill: { '#ffffff': '#d8ff00' },
  69. delay: 'rand(10, 150)',
  70. pathScale: 'rand(0.7, 0.8)',
  71. degreeShift: 20 } });
  72. document.addEventListener('click', function (e) {
  73. burst_tune.
  74. generate().
  75. tune({ x: e.pageX, y: e.pageY }).
  76. replay();
  77. burst_tune_2.
  78. generate().
  79. tune({ x: e.pageX, y: e.pageY }).
  80. replay();
  81. });
  82. // Create the firework lines
  83. const FW_OPTS = {
  84. shape: 'curve',
  85. fill: 'none',
  86. isShowStart: false,
  87. strokeWidth: { 3: 0 },
  88. stroke: '#ffffff',
  89. strokeDasharray: '100%',
  90. strokeDashoffset: { '-100%': '100%' },
  91. duration: 1000 };
  92. const fw1 = new mojs.Shape({
  93. ...FW_OPTS,
  94. radius: 170,
  95. radiusY: 20,
  96. top: '100%',
  97. y: -165,
  98. angle: 75,
  99. onStart: function () {
  100. burst1.replay(0);
  101. burst1_2.replay(0);
  102. } });
  103. const fw2 = new mojs.Shape({
  104. ...FW_OPTS,
  105. radius: 180,
  106. radiusY: 50,
  107. top: '100%',
  108. x: 50,
  109. y: -155,
  110. strokeDashoffset: { '100%': '-100%' },
  111. angle: -60,
  112. delay: 200,
  113. onStart: function () {
  114. burst2.replay(0);
  115. burst2_2.replay(0);
  116. } });
  117. // Underline under title
  118. const underline = new mojs.Shape({
  119. parent: document.getElementById('title'),
  120. shape: 'curve',
  121. strokeLinecap: 'round',
  122. fill: 'none',
  123. isShowStart: false,
  124. strokeWidth: { '1em': '5em' },
  125. stroke: '#ffffff',
  126. strokeDasharray: '200%',
  127. strokeDashoffset: { '200%': '100%' },
  128. radius: 150,
  129. radiusY: 10,
  130. y: '1.1em',
  131. angle: -10,
  132. duration: 2000,
  133. delay: 1000 }).
  134. then({
  135. strokeWidth: { '5em': '1em' },
  136. strokeDashoffset: { '100%': '-200%' },
  137. duration: 2000,
  138. delay: 10000 });
  139. const timelineText = new mojs.Timeline({
  140. repeat: 2018 }).
  141. add(underline).
  142. play();
  143. // Fire off the explosions
  144. const timeline = new mojs.Timeline({
  145. repeat: 2018 }).
  146. add([fw1, fw2]).
  147. play();
  148. // Create sounds
  149. // var explosion = new Audio("https://www.freesound.org/data/previews/21/21410_21830-lq.mp3"); // buffers automatically when created
  150. // explosion.play();

结论

所有代码拷贝后即可运行,如果有问题的可以联系作者!

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

闽ICP备14008679号