当前位置:   article > 正文

分享亿个HTML炫酷特效代码_炫酷的html代码

炫酷的html代码

目录

一、黑客帝国代码雨

二、发光的文字(可编辑)

三、粒子风暴

四、炫酷鼠标移动特效

五、旋转的星空

六、旋转的立方体


一、黑客帝国代码雨

新建一个文本文档,打开

上代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>黑客帝国代码雨</title>
  5. </head>
  6. <body> <canvas id="canvas"></canvas>
  7. <style type="text/css">
  8. body {
  9. margin: 0;
  10. padding: 0;
  11. overflow: hidden;
  12. }
  13. </style>
  14. <script type="text/javascript">
  15. var canvas = document.getElementById('canvas');
  16. var ctx = canvas.getContext('2d');
  17. canvas.height = window.innerHeight;
  18. canvas.width = window.innerWidth;
  19. var texts = '156dsfcac'.split('');
  20. var fontSize = 16;
  21. var columns = canvas.width / fontSize;
  22. // 用于计算输出文字时坐标,所以长度即为列数
  23. var drops = [];
  24. //初始值
  25. for (var x = 0; x < columns; x++) {
  26. drops[x] = 1;
  27. }
  28. function draw() {
  29. //让背景逐渐由透明到不透明
  30. ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
  31. ctx.fillRect(0, 0, canvas.width, canvas.height);
  32. //文字颜色
  33. ctx.fillStyle = '#0F0';
  34. ctx.font = fontSize + 'px arial';
  35. //逐行输出文字
  36. for (var i = 0; i < drops.length; i++) {
  37. var text = texts[Math.floor(Math.random() * texts.length)];
  38. ctx.fillText(text, i * fontSize, drops[i] * fontSize);
  39. if (drops[i] * fontSize > canvas.height || Math.random() > 0.95) {
  40. drops[i] = 0;
  41. }
  42. drops[i]++;
  43. }
  44. }
  45. setInterval(draw, 33);
  46. </script>
  47. </body>
  48. </html>

后缀改成.html

我以前的作品也有这个教程,链接:教你成为机房最靓的仔-CSDN博客

运行效果:

二、发光的文字(可编辑)

新建文本文档,打开

上代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. *{
  10. /* 初始化 */
  11. margin: 0;
  12. padding: 0;
  13. }
  14. body{
  15. /* 100% 窗口高度 */
  16. min-height: 100vh;
  17. width: 100%;
  18. /* 弹性布局 水平+垂直居中 */
  19. display: flex;
  20. justify-content: center;
  21. align-items: center;
  22. background-color: #06252e;
  23. }
  24. .box{
  25. width: 100%;
  26. /* 投影效果 */
  27. -webkit-box-reflect:below 1px linear-gradient(transparent, rgba(0,0,0,0.2));
  28. }
  29. h1{
  30. color: #fff;
  31. font-size: 96px;
  32. /* 字间距 */
  33. letter-spacing: 15px;
  34. /* 转大写 */
  35. text-transform: uppercase;
  36. text-align: center;
  37. line-height: 76px;
  38. outline: none;
  39. /* 自定义属性 --c,可通过 var 函数对其调用 */
  40. --c:lightseagreen;
  41. /* 调用自定义属性--c,设置文字阴影(发光效果) */
  42. text-shadow: 0 0 10px var(--c),
  43. 0 0 20px var(--c),
  44. 0 0 40px var(--c),
  45. 0 0 80px var(--c),
  46. 0 0 160px var(--c);
  47. /* 执行动画:动画名 时长 线性的 无限次播放 */
  48. animation: animate 5s linear infinite;
  49. }
  50. /* 定义动画 */
  51. @keyframes animate{
  52. to{
  53. /* 色相旋转过滤镜(设置度数可改变颜色) */
  54. filter: hue-rotate(360deg);
  55. }
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div class="box">
  61. <h1 contenteditable="true">hello</h1>
  62. </div>
  63. </body>
  64. </html>

后缀改成.html

运行效果:

三、粒子风暴

新建文本文档,打开

输入代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>粒子效果</title>
  6. <style>
  7. html,body{
  8. margin:0px;
  9. width:100%;
  10. height:100%;
  11. overflow:hidden;
  12. background:#000;
  13. }
  14. #canvas{
  15. position:absolute;
  16. width:100%;
  17. height:100%;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <canvas id="canvas"></canvas>
  23. <script>
  24. function project3D(x,y,z,vars){
  25. var p,d;
  26. x-=vars.camX;
  27. y-=vars.camY-8;
  28. z-=vars.camZ;
  29. p=Math.atan2(x,z);
  30. d=Math.sqrt(x*x+z*z);
  31. x=Math.sin(p-vars.yaw)*d;
  32. z=Math.cos(p-vars.yaw)*d;
  33. p=Math.atan2(y,z);
  34. d=Math.sqrt(y*y+z*z);
  35. y=Math.sin(p-vars.pitch)*d;
  36. z=Math.cos(p-vars.pitch)*d;
  37. var rx1=-1000;
  38. var ry1=1;
  39. var rx2=1000;
  40. var ry2=1;
  41. var rx3=0;
  42. var ry3=0;
  43. var rx4=x;
  44. var ry4=z;
  45. var uc=(ry4-ry3)*(rx2-rx1)-(rx4-rx3)*(ry2-ry1);
  46. var ua=((rx4-rx3)*(ry1-ry3)-(ry4-ry3)*(rx1-rx3))/uc;
  47. var ub=((rx2-rx1)*(ry1-ry3)-(ry2-ry1)*(rx1-rx3))/uc;
  48. if(!z)z=0.000000001;
  49. if(ua>0&&ua<1&&ub>0&&ub<1){
  50. return {
  51. x:vars.cx+(rx1+ua*(rx2-rx1))*vars.scale,
  52. y:vars.cy+y/z*vars.scale,
  53. d:(x*x+y*y+z*z)
  54. };
  55. }else{
  56. return { d:-1 };
  57. }
  58. }
  59. function elevation(x,y,z){
  60. var dist = Math.sqrt(x*x+y*y+z*z);
  61. if(dist && z/dist>=-1 && z/dist <=1) return Math.acos(z / dist);
  62. return 0.00000001;
  63. }
  64. function rgb(col){
  65. col += 0.000001;
  66. var r = parseInt((0.5+Math.sin(col)*0.5)*16);
  67. var g = parseInt((0.5+Math.cos(col)*0.5)*16);
  68. var b = parseInt((0.5-Math.sin(col)*0.5)*16);
  69. return "#"+r.toString(16)+g.toString(16)+b.toString(16);
  70. }
  71. function interpolateColors(RGB1,RGB2,degree){
  72. var w2=degree;
  73. var w1=1-w2;
  74. return [w1*RGB1[0]+w2*RGB2[0],w1*RGB1[1]+w2*RGB2[1],w1*RGB1[2]+w2*RGB2[2]];
  75. }
  76. function rgbArray(col){
  77. col += 0.000001;
  78. var r = parseInt((0.5+Math.sin(col)*0.5)*256);
  79. var g = parseInt((0.5+Math.cos(col)*0.5)*256);
  80. var b = parseInt((0.5-Math.sin(col)*0.5)*256);
  81. return [r, g, b];
  82. }
  83. function colorString(arr){
  84. var r = parseInt(arr[0]);
  85. var g = parseInt(arr[1]);
  86. var b = parseInt(arr[2]);
  87. return "#"+("0" + r.toString(16) ).slice (-2)+("0" + g.toString(16) ).slice (-2)+("0" + b.toString(16) ).slice (-2);
  88. }
  89. function process(vars){
  90. if(vars.points.length<vars.initParticles) for(var i=0;i<5;++i) spawnParticle(vars);
  91. var p,d,t;
  92. p = Math.atan2(vars.camX, vars.camZ);
  93. d = Math.sqrt(vars.camX * vars.camX + vars.camZ * vars.camZ);
  94. d -= Math.sin(vars.frameNo / 80) / 25;
  95. t = Math.cos(vars.frameNo / 300) / 165;
  96. vars.camX = Math.sin(p + t) * d;
  97. vars.camZ = Math.cos(p + t) * d;
  98. vars.camY = -Math.sin(vars.frameNo / 220) * 15;
  99. vars.yaw = Math.PI + p + t;
  100. vars.pitch = elevation(vars.camX, vars.camZ, vars.camY) - Math.PI / 2;
  101. var t;
  102. for(var i=0;i<vars.points.length;++i){
  103. x=vars.points[i].x;
  104. y=vars.points[i].y;
  105. z=vars.points[i].z;
  106. d=Math.sqrt(x*x+z*z)/1.0075;
  107. t=.1/(1+d*d/5);
  108. p=Math.atan2(x,z)+t;
  109. vars.points[i].x=Math.sin(p)*d;
  110. vars.points[i].z=Math.cos(p)*d;
  111. vars.points[i].y+=vars.points[i].vy*t*((Math.sqrt(vars.distributionRadius)-d)*2);
  112. if(vars.points[i].y>vars.vortexHeight/2 || d<.25){
  113. vars.points.splice(i,1);
  114. spawnParticle(vars);
  115. }
  116. }
  117. }
  118. function drawFloor(vars){
  119. var x,y,z,d,point,a;
  120. for (var i = -25; i <= 25; i += 1) {
  121. for (var j = -25; j <= 25; j += 1) {
  122. x = i*2;
  123. z = j*2;
  124. y = vars.floor;
  125. d = Math.sqrt(x * x + z * z);
  126. point = project3D(x, y-d*d/85, z, vars);
  127. if (point.d != -1) {
  128. size = 1 + 15000 / (1 + point.d);
  129. a = 0.15 - Math.pow(d / 50, 4) * 0.15;
  130. if (a > 0) {
  131. vars.ctx.fillStyle = colorString(interpolateColors(rgbArray(d/26-vars.frameNo/40),[0,128,32],.5+Math.sin(d/6-vars.frameNo/8)/2));
  132. vars.ctx.globalAlpha = a;
  133. vars.ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
  134. }
  135. }
  136. }
  137. }
  138. vars.ctx.fillStyle = "#82f";
  139. for (var i = -25; i <= 25; i += 1) {
  140. for (var j = -25; j <= 25; j += 1) {
  141. x = i*2;
  142. z = j*2;
  143. y = -vars.floor;
  144. d = Math.sqrt(x * x + z * z);
  145. point = project3D(x, y+d*d/85, z, vars);
  146. if (point.d != -1) {
  147. size = 1 + 15000 / (1 + point.d);
  148. a = 0.15 - Math.pow(d / 50, 4) * 0.15;
  149. if (a > 0) {
  150. vars.ctx.fillStyle = colorString(interpolateColors(rgbArray(-d/26-vars.frameNo/40),[32,0,128],.5+Math.sin(-d/6-vars.frameNo/8)/2));
  151. vars.ctx.globalAlpha = a;
  152. vars.ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. function sortFunction(a,b){
  159. return b.dist-a.dist;
  160. }
  161. function draw(vars){
  162. vars.ctx.globalAlpha=.15;
  163. vars.ctx.fillStyle="#000";
  164. vars.ctx.fillRect(0, 0, canvas.width, canvas.height);
  165. drawFloor(vars);
  166. var point,x,y,z,a;
  167. for(var i=0;i<vars.points.length;++i){
  168. x=vars.points[i].x;
  169. y=vars.points[i].y;
  170. z=vars.points[i].z;
  171. point=project3D(x,y,z,vars);
  172. if(point.d != -1){
  173. vars.points[i].dist=point.d;
  174. size=1+vars.points[i].radius/(1+point.d);
  175. d=Math.abs(vars.points[i].y);
  176. a = .8 - Math.pow(d / (vars.vortexHeight/2), 1000) * .8;
  177. vars.ctx.globalAlpha=a>=0&&a<=1?a:0;
  178. vars.ctx.fillStyle=rgb(vars.points[i].color);
  179. if(point.x>-1&&point.x<vars.canvas.width&&point.y>-1&&point.y<vars.canvas.height)vars.ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
  180. }
  181. }
  182. vars.points.sort(sortFunction);
  183. }
  184. function spawnParticle(vars){
  185. var p,ls;
  186. pt={};
  187. p=Math.PI*2*Math.random();
  188. ls=Math.sqrt(Math.random()*vars.distributionRadius);
  189. pt.x=Math.sin(p)*ls;
  190. pt.y=-vars.vortexHeight/2;
  191. pt.vy=vars.initV/20+Math.random()*vars.initV;
  192. pt.z=Math.cos(p)*ls;
  193. pt.radius=200+800*Math.random();
  194. pt.color=pt.radius/1000+vars.frameNo/250;
  195. vars.points.push(pt);
  196. }
  197. function frame(vars) {
  198. if(vars === undefined){
  199. var vars={};
  200. vars.canvas = document.querySelector("canvas");
  201. vars.ctx = vars.canvas.getContext("2d");
  202. vars.canvas.width = document.body.clientWidth;
  203. vars.canvas.height = document.body.clientHeight;
  204. window.addEventListener("resize", function(){
  205. vars.canvas.width = document.body.clientWidth;
  206. vars.canvas.height = document.body.clientHeight;
  207. vars.cx=vars.canvas.width/2;
  208. vars.cy=vars.canvas.height/2;
  209. }, true);
  210. vars.frameNo=0;
  211. vars.camX = 0;
  212. vars.camY = 0;
  213. vars.camZ = -14;
  214. vars.pitch = elevation(vars.camX, vars.camZ, vars.camY) - Math.PI / 2;
  215. vars.yaw = 0;
  216. vars.cx=vars.canvas.width/2;
  217. vars.cy=vars.canvas.height/2;
  218. vars.bounding=10;
  219. vars.scale=500;
  220. vars.floor=26.5;
  221. vars.points=[];
  222. vars.initParticles=700;
  223. vars.initV=.01;
  224. vars.distributionRadius=800;
  225. vars.vortexHeight=25;
  226. }
  227. vars.frameNo++;
  228. requestAnimationFrame(function() {
  229. frame(vars);
  230. });
  231. process(vars);
  232. draw(vars);
  233. }
  234. frame();
  235. </script>
  236. <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
  237. <p><a href="http://sc.chinaz.com/" target="_blank"></a></p>
  238. </div>
  239. </body>
  240. </html>

后缀改成.html

运行效果:

四、炫酷鼠标移动特效

新建文本文档,打开

输入代码:
 

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  3. <head>
  4. <title>star</title>
  5. <script type="text/javascript">
  6. window.onload = function () {
  7. C = Math.cos; // cache Math objects
  8. S = Math.sin;
  9. U = 0;
  10. w = window;
  11. j = document;
  12. d = j.getElementById("c");
  13. c = d.getContext("2d");
  14. W = d.width = w.innerWidth;
  15. H = d.height = w.innerHeight;
  16. c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
  17. c.globalCompositeOperation = "lighter"; // switch to additive color application
  18. c.lineWidth = 0.2;
  19. c.lineCap = "round";
  20. var bool = 0,
  21. t = 0; // theta
  22. d.onmousemove = function (e) {
  23. if(window.T) {
  24. if(D==9) { D=Math.random()*15; f(1); }
  25. clearTimeout(T);
  26. }
  27. X = e.pageX; // grab mouse pixel coords
  28. Y = e.pageY;
  29. a=0; // previous coord.x
  30. b=0; // previous coord.y
  31. A = X, // original coord.x
  32. B = Y; // original coord.y
  33. R=(e.pageX/W * 999>>0)/999;
  34. r=(e.pageY/H * 999>>0)/999;
  35. U=e.pageX/H * 360 >>0;
  36. D=9;
  37. g = 360 * Math.PI / 180;
  38. T = setInterval(f = function (e) { // start looping spectrum
  39. c.save();
  40. c.globalCompositeOperation = "source-over"; // switch to additive color application
  41. if(e!=1) {
  42. c.fillStyle = "rgba(0,0,0,0.02)";
  43. c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
  44. }
  45. c.restore();
  46. i = 25; while(i --) {
  47. c.beginPath();
  48. if(D > 450 || bool) { // decrease diameter
  49. if(!bool) { // has hit maximum
  50. bool = 1;
  51. }
  52. if(D < 0.1) { // has hit minimum
  53. bool = 0;
  54. }
  55. t -= g; // decrease theta
  56. D -= 0.1; // decrease size
  57. }
  58. if(!bool) {
  59. t += g; // increase theta
  60. D += 0.1; // increase size
  61. }
  62. q = (R / r - 1) * t; // create hypotrochoid from current mouse position, and setup variables (see: http://en.wikipedia.org/wiki/Hypotrochoid)
  63. x = (R - r) * C(t) + D * C(q) + (A + (X - A) * (i / 25)) + (r - R); // center on xy coords
  64. y = (R - r) * S(t) - D * S(q) + (B + (Y - B) * (i / 25));
  65. if (a) { // draw once two points are set
  66. c.moveTo(a, b);
  67. c.lineTo(x, y)
  68. }
  69. c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; // draw rainbow hypotrochoid
  70. c.stroke();
  71. a = x; // set previous coord.x
  72. b = y; // set previous coord.y
  73. }
  74. U -= 0.5; // increment hue
  75. A = X; // set original coord.x
  76. B = Y; // set original coord.y
  77. }, 16);
  78. }
  79. j.onkeydown = function(e) { a=b=0; R += 0.05 }
  80. d.onmousemove({pageX:300, pageY:290})
  81. }
  82. </script>
  83. </head>
  84. <body style="margin:0px;padding:0px;width:100%;height:100%;overflow:hidden;">
  85. <canvas id="c"></canvas>
  86. </body>
  87. </html>

后缀改成.html

运行效果:

五、旋转的星空

新建文本文档,打开

上代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>旋转的星空</title>
  6. <style type="text/css">
  7. body{background: black;padding: 0;margin: 0; overflow:hidden}
  8. .header{margin: 0 auto;width: 100%;height: 100%;background-color: #000;position: relative;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="header"><canvas id="canvas"></canvas></div>
  13. <script>
  14. var canvas = document.getElementById('canvas'),
  15. ctx = canvas.getContext('2d'),
  16. w = canvas.width = window.innerWidth,
  17. h = canvas.height = window.innerHeight,
  18. hue = 217,
  19. stars = [],
  20. count = 0,
  21. maxStars = 3000;//星星数量
  22. var canvas2 = document.createElement('canvas'),
  23. ctx2 = canvas2.getContext('2d');
  24. canvas2.width = 100;
  25. canvas2.height = 100;
  26. var half = canvas2.width / 2,
  27. gradient2 = ctx2.createRadialGradient(half, half, 0, half, half, half);
  28. gradient2.addColorStop(0.025, '#CCC');
  29. gradient2.addColorStop(0.1, 'hsl(' + hue + ', 61%, 33%)');
  30. gradient2.addColorStop(0.25, 'hsl(' + hue + ', 64%, 6%)');
  31. gradient2.addColorStop(1, 'transparent');
  32. ctx2.fillStyle = gradient2;
  33. ctx2.beginPath();
  34. ctx2.arc(half, half, half, 0, Math.PI * 2);
  35. ctx2.fill();
  36. // End cache
  37. function random(min, max) {
  38. if (arguments.length < 2) {
  39. max = min;
  40. min = 0;
  41. }
  42. if (min > max) {
  43. var hold = max;
  44. max = min;
  45. min = hold;
  46. }
  47. return Math.floor(Math.random() * (max - min + 1)) + min;
  48. }
  49. function maxOrbit(x, y) {
  50. var max = Math.max(x, y),
  51. diameter = Math.round(Math.sqrt(max * max + max * max));
  52. return diameter / 2;
  53. //星星移动范围,值越大范围越小,
  54. }
  55. var Star = function() {
  56. this.orbitRadius = random(maxOrbit(w, h));
  57. this.radius = random(60, this.orbitRadius) / 8;
  58. //星星大小
  59. this.orbitX = w / 2;
  60. this.orbitY = h / 2;
  61. this.timePassed = random(0, maxStars);
  62. this.speed = random(this.orbitRadius) / 50000;
  63. //星星移动速度
  64. this.alpha = random(2, 10) / 10;
  65. count++;
  66. stars[count] = this;
  67. }
  68. Star.prototype.draw = function() {
  69. var x = Math.sin(this.timePassed) * this.orbitRadius + this.orbitX,
  70. y = Math.cos(this.timePassed) * this.orbitRadius + this.orbitY,
  71. twinkle = random(10);
  72. if (twinkle === 1 && this.alpha > 0) {
  73. this.alpha -= 0.05;
  74. } else if (twinkle === 2 && this.alpha < 1) {
  75. this.alpha += 0.05;
  76. }
  77. ctx.globalAlpha = this.alpha;
  78. ctx.drawImage(canvas2, x - this.radius / 2, y - this.radius / 2, this.radius, this.radius);
  79. this.timePassed += this.speed;
  80. }
  81. for (var i = 0; i < maxStars; i++) {
  82. new Star();
  83. }
  84. function animation() {
  85. ctx.globalCompositeOperation = 'source-over';
  86. ctx.globalAlpha = 0.5; //尾巴
  87. ctx.fillStyle = 'hsla(' + hue + ', 64%, 6%, 2)';
  88. ctx.fillRect(0, 0, w, h)
  89. ctx.globalCompositeOperation = 'lighter';
  90. for (var i = 1, l = stars.length; i < l; i++) {
  91. stars[i].draw();
  92. };
  93. window.requestAnimationFrame(animation);
  94. }
  95. animation();
  96. </script>
  97. </body>
  98. </html>

后缀改成.html

运行效果:

六、旋转的立方体

新建文本文档,打开

直接上代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>旋转立方体</title>
  6. <style>
  7. #cube {
  8. width: 200px;
  9. height: 200px;
  10. position: relative;
  11. transform-style: preserve-3d;
  12. animation: rotate 6s infinite linear;
  13. margin: 100px auto;
  14. }
  15. #cube div {
  16. position: absolute;
  17. width: 200px;
  18. height: 200px;
  19. background-color: rgba(0, 255, 255, 0.5);
  20. border: 2px solid #333;
  21. }
  22. #cube .front {
  23. transform: translateZ(100px);
  24. }
  25. #cube .back {
  26. transform: rotateY(180deg) translateZ(100px);
  27. }
  28. #cube .right {
  29. transform: rotateY(90deg) translateZ(100px);
  30. }
  31. #cube .left {
  32. transform: rotateY(-90deg) translateZ(100px);
  33. }
  34. #cube .top {
  35. transform: rotateX(90deg) translateZ(100px);
  36. }
  37. #cube .bottom {
  38. transform: rotateX(-90deg) translateZ(100px);
  39. }
  40. @keyframes rotate {
  41. 0% {
  42. transform: rotateX(0) rotateY(0) rotateZ(0);
  43. }
  44. 100% {
  45. transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
  46. }
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div id="cube">
  52. <div class="front"></div>
  53. <div class="back"></div>
  54. <div class="right"></div>
  55. <div class="left"></div>
  56. <div class="top"></div>
  57. <div class="bottom"></div>
  58. </div>
  59. <script>
  60. const cube = document.querySelector('#cube');
  61. let isPaused = false;
  62. cube.addEventListener('mouseover', () => {
  63. isPaused = true;
  64. cube.style.animationPlayState = 'paused';
  65. });
  66. cube.addEventListener('mouseout', () => {
  67. isPaused = false;
  68. cube.style.animationPlayState = 'running';
  69. });
  70. setInterval(() => {
  71. if (!isPaused) {
  72. cube.style.animationPlayState = 'running';
  73. }
  74. }, 1000);
  75. </script>
  76. </body>
  77. </html>

后缀改成.html

运行效果:

先做到这了,以后再有我会接着做,886!

附:HTML小指南(转载Carefree1990大神的作品)

原链接:https://blog.csdn.net/weixin_42400955/article/details/81106697

资源下载放在文章顶部了

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号