htm特效代码

这是第二篇,第一篇在我的主页。

9.神经粒子特效

<!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="UTF-8">

    <title>网状粒子效果1</title>

    <style>

    html, body {

    margin: 0;

    padding: 0;

    height: 100%;

    overflow: hidden;

    }

    </style>

    </head>

    <body>

    <canvas id="cas" position : absolute;z-index : -1;></canvas>




    <script>

    var canvas = document.getElementById("cas");

    var ctx = canvas.getContext("2d");




    resize();

    window.onresize = resize;




    function resize() {

    canvas.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

    canvas.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

    }




    var RAF = (function() {

    return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {

    window.setTimeout(callback, 1000 / 60);

    };

    })();




    // 鼠标活动时,获取鼠标坐标

    var warea = {x: null, y: null, max: 20000};

    window.onmousemove = function(e) {

    e = e || window.event;




    warea.x = e.clientX;

    warea.y = e.clientY;

    };

    window.onmouseout = function(e) {

    warea.x = null;

    warea.y = null;

    };




    // 添加粒子

    // x,y为粒子坐标,xa, ya为粒子xy轴加速度,max为连线的最大距离

    var dots = [];

    for (var i = 0; i < 300; i++) {

    var x = Math.random() * canvas.width;

    var y = Math.random() * canvas.height;

    var xa = Math.random() * 2 - 1;

    var ya = Math.random() * 2 - 1;




    dots.push({

    x: x,

    y: y,

    xa: xa,

    ya: ya,

    max: 6000

    })

    }




    // 延迟100秒开始执行动画,如果立即执行有时位置计算会出错

    setTimeout(function() {

    animate();

    }, 100);




    // 每一帧循环的逻辑

    function animate() {

    ctx.clearRect(0, 0, canvas.width, canvas.height);




    // 将鼠标坐标添加进去,产生一个用于比对距离的点数组

    var ndots = [warea].concat(dots);




    dots.forEach(function(dot) {




    // 粒子位移

    dot.x += dot.xa;

    dot.y += dot.ya;




    // 遇到边界将加速度反向

    dot.xa *= (dot.x > canvas.width || dot.x < 0) ? -1 : 1;

    dot.ya *= (dot.y > canvas.height || dot.y < 0) ? -1 : 1;




    // 绘制点

    ctx.fillRect(dot.x - 0.5, dot.y - 0.5, 1, 1);




    // 循环比对粒子间的距离

    for (var i = 0; i < ndots.length; i++) {

    var d2 = ndots[i];




    if (dot === d2 || d2.x === null || d2.y === null) continue;




    var xc = dot.x - d2.x;

    var yc = dot.y - d2.y;




    // 两个粒子之间的距离

    var dis = xc * xc + yc * yc;




    // 距离比

    var ratio;




    // 如果两个粒子之间的距离小于粒子对象的max值,则在两个粒子间画线

    if (dis < d2.max) {




    // 如果是鼠标,则让粒子向鼠标的位置移动

    if (d2 === warea && dis > (d2.max / 2)) {

    dot.x -= xc * 0.03;

    dot.y -= yc * 0.03;

    }




    // 计算距离比

    ratio = (d2.max - dis) / d2.max;




    // 画线

    ctx.beginPath();

    ctx.lineWidth = ratio / 2;

    ctx.strokeStyle = 'rgba(0,0,0,' + (ratio + 0.2) + ')';

    ctx.moveTo(dot.x, dot.y);

    ctx.lineTo(d2.x, d2.y);

    ctx.stroke();

    }

    }




    // 将已经计算过的粒子从数组中删除

    ndots.splice(ndots.indexOf(dot), 1);

    });




    RAF(animate);

    }

    </script>

    </body>

    </html>

10.三维波浪:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>波浪的方式</title>
 
<style>
html, body {
	overflow: hidden;
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	background:#000;
}
canvas {
	position: absolute;
	width: 100%;
	height: 100%;
	background:#000;
}</style>
 
</head>
<body>
 
  <script>
"use strict";
// webGL line_strip
const webGL = {
	init(options) {
		this.elem = document.querySelector("canvas");
		this.gl = (
			this.elem.getContext("webgl", options) ||
			this.elem.getContext("experimental-webgl", options)
		);
		if (!this.gl) return false;
		const vertexShader = this.gl.createShader(this.gl.VERTEX_SHADER);
		this.gl.shaderSource(vertexShader, `
			precision highp float;
			attribute vec2 aPosition;
			uniform vec3 uHSV;
			uniform vec2 uResolution;
			varying vec4 vColor;
			vec3 hsv2rgb(vec3 c) {
				vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
				vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
				return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
			}
			void main() {
				gl_PointSize = 1.0;
				gl_Position = vec4(
					( aPosition.x / uResolution.x * 2.0) - 1.0, 
					(-aPosition.y / uResolution.y * 2.0) + 1.0, 
					0.0,
					1.0
				);
				vColor = vec4(hsv2rgb(uHSV), 1.0);
			}
		`);
		this.gl.compileShader(vertexShader);
		const fragmentShader = this.gl.createShader(this.gl.FRAGMENT_SHADER);
		this.gl.shaderSource(fragmentShader, `
			precision highp float;
			varying vec4 vColor;
			void main() {
				gl_FragColor = vColor;
			}
		`);
		this.gl.compileShader(fragmentShader);
		this.program = this.gl.createProgram();
		this.gl.attachShader(this.program, vertexShader);
		this.gl.attachShader(this.program, fragmentShader);
		this.gl.linkProgram(this.program);
		this.gl.useProgram(this.program);
		this.aPosition = this.gl.getAttribLocation(this.program, "aPosition");
		this.gl.enableVertexAttribArray(this.aPosition);
		this.positionBuffer = this.gl.createBuffer();
		this.uHSV = this.gl.getUniformLocation(this.program, "uHSV");
		this.gl.enableVertexAttribArray(this.uHSV);
		this.resize();
		window.addEventListener("resize", () => this.resize(), false);
		return this;
	},
	resize () {
		this.width = this.elem.width = this.elem.offsetWidth;
		this.height = this.elem.height = this.elem.offsetHeight;
		const uResolution = this.gl.getUniformLocation(this.program, "uResolution");
		this.gl.enableVertexAttribArray(uResolution);
		this.gl.uniform2f(uResolution, this.width, this.height);
		this.gl.viewport(0, 0,
			this.gl.drawingBufferWidth,
			this.gl.drawingBufferHeight
		);
	},
	blend (s, d) {
		this.gl.blendFunc(s, d);
		this.gl.enable(this.gl.BLEND);
	},
	createBufferLine (len) {
		this.num = len;
		this.bufferLine = new Float32Array(len * 2);
	},
	beginPath () {
		this.k = 0;
	},
	strokeStyle (h, s, v) {
		this.gl.uniform3f(this.uHSV, h, s, v);
	},
	lineTo (x, y) {
		this.bufferLine[this.k++] = x;
		this.bufferLine[this.k++] = y;
	},
	stroke () {
		this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer);
		this.gl.vertexAttribPointer(this.aPosition, 2, this.gl.FLOAT, false, 0, 0);
		this.gl.bufferData(
			this.gl.ARRAY_BUFFER,
			this.bufferLine,
			this.gl.DYNAMIC_DRAW
		);
		this.gl.drawArrays(this.gl.LINE_STRIP, 0, this.num);
	}
};
</script>
 
<canvas></canvas>
 
<script>
"use strict";
{
	const perlin = {
		init() {
			this.p = new Uint8Array(512);
			const p = new Uint8Array(256);
			for (let i = 0; i < 256; i++) p[i] = i;
			for (let i = 255; i > 0; i--) {
				const n = Math.floor((i + 1) * Math.random());
				[p[i], p[n]] = [p[n], p[i]];
			}
			for (let i = 0; i < 512; i++) this.p[i] = p[i & 255];
		},
		fade(t) {
			return t * t * t * (t * (t * 6 - 15) + 10);
		},
		lerp(t, a, b) {
			return a + t * (b - a);
		},
		grad(hash, x, y, z) {
			const h = hash & 15;
			const u = h < 8 ? x : y;
			const v = h < 4 ? y : h == 12 || h == 14 ? x : z;
			return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
		},
		noise(xi, yi, zi) {
			const X = Math.floor(xi) & 255;
			const Y = Math.floor(yi) & 255;
			const Z = Math.floor(zi) & 255;
			const x = xi - Math.floor(xi);
			const y = yi - Math.floor(yi);
			const z = zi - Math.floor(zi);
			const u = this.fade(x);
			const v = this.fade(y);
			const w = this.fade(z);
			const A = this.p[X] + Y;
			const AA = this.p[A] + Z;
			const AB = this.p[A + 1] + Z;
			const B = this.p[X + 1] + Y;
			const BA = this.p[B] + Z;
			const BB = this.p[B + 1] + Z;
			return this.lerp(
				w,
				this.lerp(
					v,
					this.lerp(u, this.grad(this.p[AA], x, y, z), this.grad(this.p[BA], x - 1, y, z)),
					this.lerp(u, this.grad(this.p[AB], x, y - 1, z), this.grad(this.p[BB], x - 1, y - 1, z))
				),
				this.lerp(
					v,
					this.lerp(u, this.grad(this.p[AA + 1], x, y, z - 1), this.grad(this.p[BA + 1], x - 1, y, z - 1)),
					this.lerp(
						u,
						this.grad(this.p[AB + 1], x, y - 1, z - 1),
						this.grad(this.p[BB + 1], x - 1, y - 1, z - 1)
					)
				)
			);
		}
	};
	const canvas = webGL.init({
		alpha: false,
		stencil: false,
		antialias: false,
		depth: false,
	});
	canvas.blend(canvas.gl.ONE, canvas.gl.ONE);
	perlin.init();
	canvas.createBufferLine(100);
	let z = 0;
	function run() {
		const sw = canvas.width / 100;
		const sh = sw * 30;
		for (let i = 0; i < 180; i++) {
			canvas.beginPath();
			canvas.strokeStyle(
				z + i / 360,
				0.5,
				0.3
			);
			for (let j = -50; j < 50; j++) {
				const h = perlin.noise(j * 0.05, z - i * 0.01, z);
				canvas.lineTo(
					canvas.width * 0.5 + 0.01 * (i + 180) * j * sw * 0.5,
					-90 + i + canvas.height * 0.5 + h * sh
				);
			}
			canvas.stroke();
		}
		z += 0.0025;
		requestAnimationFrame(run);
	}
	run();
}
</script>
 
</body>
</html>

11.太阳系

<html>
	<head>
		<meta charset="UTF-8">
		<title>太阳星星系</title>
		<style type="text/css">
		@keyframes rotate{
				from{
					transform: rotate(0deg);
				}
				to{
					transform: rotate(-360deg);
				}
			}
			*{
				box-sizing: border-box;
			}
			html,body{
				width: 100%;
				height: 100%;
				margin: 0;
			}
			.solarsys{
				width: 80%;
				height: 100%;
				background-color:#000000;
				margin: 0 auto;
				position: relative;
			}
			.solarsys div{
				position: absolute;
				border-radius: 50%;
			}
			.sun{
				width: 150px;
				height: 150px;
				background:#f05121;
				box-shadow:1px 1px 20px #fbebbb;
				top: calc(50% - 75px);
				left: calc(50% - 75px);
			}
			.sun>img{
				width: 149px;
				height: 149px;
				border-radius: 50%;
			}
			.marsOrbit{
				width: 180px;
				height: 180px;
				border: 1px dashed #FA8008;
				top: calc(50% - 90px);
				left: calc(50% - 90px);
			}
			.mercury{
				width: 10px;
				height: 10px;
				background:dodgerblue;
				top: calc(50% - 5px);
				left: calc(50% - 95px);
				/*围绕圆心旋转*/
				transform-origin:95px 5px ;
				animation: rotate 0.8s linear infinite;
			}
			/*金星*/
			.venusOrbit{
				width: 240px;
				height: 240px;
				border: 1px dashed #ffffff;
				top: calc(50% - 120px);
				left: calc(50% - 120px);
			}
			.venus{
				width: 20px;
				height: 20px;
				background:yellow;
				top: calc(50% - 10px);
				left: calc(50% - 130px);
				/*围绕圆心旋转*/
				transform-origin:130px 10px ;
				animation: rotate 1.5s linear infinite;
			}
			/*地球*/
			.earthOrbit{
				width: 320px;
				height: 320px;
				border: 1px dashed #ffffff;
				top: calc(50% - 160px);
				left: calc(50% - 160px);
			}
			.earth{
				width: 15px;
				height: 15px;
				background:lightskyblue;
				top: calc(50% - 7px);
				left: calc(50% - 167px);
				/*围绕圆心旋转*/
				transform-origin:167px 7px ;
				animation: rotate 4.7s linear infinite;
			}
			/*火星*/
			.marsOrbit{
				width: 420px;
				height: 420px;
				border: 1px dashed #ffffff;
				top: calc(50% - 210px);
				left: calc(50% - 210px);
			}
			.mars{
				width: 12px;
				height: 12px;
				background:red;
				top: calc(50% - 5px);
				left: calc(50% - 215px);
				/*围绕圆心旋转*/
				transform-origin:215px 5px ;
				animation: rotate 5s linear infinite;
			}
			/*木星*/
			.jupiterOrbit{
				width: 520px;
				height: 520px;
				border: 1px dashed #ffffff;
				top: calc(50% - 260px);
				left: calc(50% - 260px);
			}
			.jupiter{
				width: 40px;
				height: 40px;
				background:green;
				top: calc(50% - 18px);
				left: calc(50% - 280px);
				/*围绕圆心旋转*/
				transform-origin:280px 18px ;
				animation: rotate 7s linear infinite;
			}
			/*土星*/
			.saturnOrbit{
				width: 580px;
				height: 580px;
				border: 1px dashed #ffffff;
				top: calc(50% - 290px);
				left: calc(50% - 290px);
			}
			.saturn{
				width: 30px;
				height: 30px;
				background:#ECCC7F;
				top: calc(50% - 10px);
				left: calc(50% - 305px);
				/*围绕圆心旋转*/
				transform-origin:305px 10px ;
				animation: rotate 4s linear infinite;
			}
			/*天王星*/
			.uranusOrbit{
				width: 620px;
				height: 620px;
				border: 1px dashed #ffffff;
				top: calc(50% - 310px);
				left: calc(50% - 310px);
			}
			.uranus{
				width: 22px;
				height: 22px;
				background:orange;
				top: calc(50% - 10px);
				left: calc(50% - 320px);
				/*围绕圆心旋转*/
				transform-origin:320px 10px ;
				animation: rotate 6s linear infinite;
			}
			/*海王星*/
			.neptuneOrbit{
				width: 660px;
				height: 660px;
				border: 1px dashed #ffffff;
				top: calc(50% - 330px);
				left: calc(50% - 330px);
			}
			.neptune{
				width: 18px;
				height: 18px;
				background:#EC7FE0;
				top: calc(50% - 10px);
				left: calc(50% - 340px);
				/*围绕圆心旋转*/
				transform-origin:340px 10px ;
				animation: rotate 10s linear infinite;
			}
		</style>
	</head>
<body>
		<div class="solarsys">
			<img src="img/20170521233836.jpg"/>
    <!--太阳-->
    <div class='sun'>
    	<img src="img/6.png (2).png"/>
    </div>

    <!--水星轨道-->
    <div class='mercuryOrbit'></div>

    <!--水星-->
    <div class='mercury'></div>

    <!--金星轨道-->
    <div class='venusOrbit'></div>

    <!--金星-->
    <div class='venus'></div>

    <!--地球轨道-->
    <div class='earthOrbit'></div>

    <!--地球-->
    <div class='earth'></div>

    <!--火星轨道-->
    <div class='marsOrbit'></div>

    <!--火星-->
    <div class='mars'></div>

    <!--木星轨道-->
    <div class='jupiterOrbit'></div>

    <!--木星-->
    <div class='jupiter'></div>

    <!--土星轨道-->
    <div class='saturnOrbit'></div>

    <!--土星-->
    <div class='saturn'></div>

    <!--天王星轨道-->
    <div class='uranusOrbit'></div>

    <!--天王星-->
    <div class='uranus'></div>

    <!--海王星轨道-->
    <div class='neptuneOrbit'></div>

    <!--海王星-->
    <div class='neptune'></div>
</div>
	</body>
</html>
<!--
	transform-orign:X Y;
	绕圆圈旋转
	X 表示 轨道半径+球体半径
	Y 表示球体边境
	绕轴旋转
	left right center X周转
	top bottom center Y轴转
	
-->

12.3D撕扯线

<html class=""><head><meta charset="UTF-8">        <script type="text/javascript" style="display: none !important;">        function cleanJS(js) {          js = js.replace(/location(s+)?=/mi, '');          js = js.replace(/top.location.+=('|")/mi, '');          js = js.replace(/location.replace/mi, '');          js = js.replace(/window(s+)?\[(s+)?("|')l/mi, '');          js = js.replace(/self(s+)?\[(s+)?("|')loc/mi, '');          return js;        }        _ogEval        = window.eval;        window.eval    = function(text) {_ogEval(cleanJS(text));};        window.open    = function(){};        window.print   = function(){};        window.innerWidth = window.outerWidth; // Fixes browser bug with it innerWidth reports 0        window.innerHeight = window.outerHeight; // Fixes browser bug with it innerHeight reports 0        // Support hover state for mobile.        window.ontouchstart = function(){};        </script>
 
<style>* {
     margin: 0;
  overflow:hidden;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;  
}
 
body {
  background:#333;
}
 
canvas {
  background:#333;
  width:1000px;
  height:376px;
  margin:0 auto;
  display:block;
}
 
#info {
  position:absolute;
  left:-1px;
  top:-1px;
  width:auto;
  max-width:380px;
  height:auto;
  background:#f2f2f2;
  border-bottom-right-radius:10px;
}
 
#top {
  background:#fff;
  width:100%;
  height:auto;
  position:relative;
  border-bottom:1px solid #eee;
}
 
p {
  font-family:Arial, sans-serif;
  color:#666;
  text-align:justify;
  font-size: 16px;
  margin:10px;
}
 
a {
  font-family:sans-serif;
  color:#444;
  text-decoration:none;
  font-size: 20px;
}
 
#site {
  float:left;
  margin: 10px;
  color: #38a;
  border-bottom:1px dashed #888;
}
 
#site:hover {
  color: #7af;
}
 
#close {
  float:right;
  margin: 10px;
}
 
#p {
  font-family: Verdana, sans-serif;
  position:absolute;
  right:10px;
  bottom:10px;
  color:#adf;
  border: 1px dashed #555;
  padding:4px 8px;
}</style></head><body>
<canvas id="c" width="1000" height="376"> </canvas>
   
<div id="info">
  <div id="top">
  <a id="close" href=""></a>
  </div>
</div>
   
   
<script src="http://s.codepen.io/assets/libs/empty.js" type="text/javascript"></script>
<script>/*
Copyright (c) 2013 lonely-pixel.com, Stuffit at codepen.io (http://codepen.io/stuffit)
 
View this and others at http://lonely-pixel.com
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
 
document.getElementById('close').onmousedown = function(e) {
  e.preventDefault();
  document.getElementById('info').style.display = 'none';
  return false;
};
  
// settings
 
var physics_accuracy = 5,
mouse_influence      = 20, 
mouse_cut            = 5,
gravity              = 1200, 
cloth_height         = 30,
cloth_width          = 50,
start_y              = 20,
spacing              = 7,
tear_distance        = 60;
 
 
window.requestAnimFrame =
window.requestAnimationFrame       ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame    ||
window.oRequestAnimationFrame      ||
window.msRequestAnimationFrame     ||
function(callback) {
    window.setTimeout(callback, 1000 / 60);
};
 
var canvas,
    ctx,
    cloth,
    boundsx,
    boundsy,
    mouse = {
        down: false,
        button: 1,
        x: 0,
        y: 0,
        px: 0,
        py: 0
    };
 
window.onload = function() {
 
    canvas = document.getElementById('c');
    ctx    = canvas.getContext('2d');
 
    canvas.width = canvas.clientWidth;
    canvas.height = 376;
 
    canvas.onmousedown = function(e) {
        mouse.button = e.which;
        mouse.px = mouse.x;
        mouse.py = mouse.y;
  var rect = canvas.getBoundingClientRect();
  mouse.x = e.clientX - rect.left,
  mouse.y = e.clientY - rect.top,
        mouse.down = true;
        e.preventDefault();
    };
 
    canvas.onmouseup = function(e) {
        mouse.down = false;
        e.preventDefault();
    };
 
    canvas.onmousemove = function(e) {
        mouse.px = mouse.x;
        mouse.py = mouse.y;
        var rect = canvas.getBoundingClientRect();
  mouse.x = e.clientX - rect.left,
  mouse.y = e.clientY - rect.top,
        e.preventDefault();
    };
 
    canvas.oncontextmenu = function(e) {
        e.preventDefault(); 
    };
 
    boundsx = canvas.width - 1;
    boundsy = canvas.height - 1;
 
    ctx.strokeStyle = 'rgba(222,222,222,0.6)';
    cloth = new Cloth();
    update();
};
 
var Point = function(x, y) {
 
    this.x = x;
    this.y = y;
    this.px = x;
    this.py = y;
    this.vx = 0;
    this.vy = 0;
    this.pin_x = null;
    this.pin_y = null;
    this.constraints = [];
};
 
Point.prototype.update = function(delta) {
 
    if (mouse.down) {
 
        var diff_x = this.x - mouse.x,
            diff_y = this.y - mouse.y,
            dist   = Math.sqrt(diff_x * diff_x + diff_y * diff_y);
 
        if (mouse.button == 1) {
 
            if(dist < mouse_influence) {
                this.px = this.x - (mouse.x - mouse.px) * 1.8;
                this.py = this.y - (mouse.y - mouse.py) * 1.8;
            }
 
        } else if (dist < mouse_cut) this.constraints = [];
    }
 
    this.add_force(0, gravity);
 
    delta *= delta;
    nx = this.x + ((this.x - this.px) * .99) + ((this.vx / 2) * delta);
    ny = this.y + ((this.y - this.py) * .99) + ((this.vy / 2) * delta);
 
    this.px = this.x;
    this.py = this.y;
 
    this.x = nx;
    this.y = ny;
 
    this.vy = this.vx = 0
};
 
Point.prototype.draw = function() {
 
    if (this.constraints.length <= 0) return;
     
    var i = this.constraints.length;
    while(i--) this.constraints[i].draw();
};
 
Point.prototype.resolve_constraints = function() {
 
    if (this.pin_x != null && this.pin_y != null) {
     
        this.x = this.pin_x;
        this.y = this.pin_y;
        return;
    }
 
    var i = this.constraints.length;
    while(i--) this.constraints[i].resolve();
 
    this.x > boundsx ? this.x = 2 * boundsx - this.x : 1 > this.x && (this.x = 2 - this.x);
    this.y < 1 ? this.y = 2 - this.y : this.y > boundsy && (this.y = 2 * boundsy - this.y);
};
 
Point.prototype.attach = function(point) {
 
    this.constraints.push(
        new Constraint(this, point)
    );
};
 
Point.prototype.remove_constraint = function(lnk) {
 
    var i = this.constraints.length;
    while(i--) if(this.constraints[i] == lnk) this.constraints.splice(i, 1);
};
 
Point.prototype.add_force = function(x, y )  {
 
    this.vx += x;
    this.vy += y;
};
 
Point.prototype.pin = function(pinx, piny) {
    this.pin_x = pinx;
    this.pin_y = piny;
};
 
var Constraint = function(p1, p2) {
 
    this.p1 = p1;
    this.p2 = p2;
    this.length = spacing;
};
 
Constraint.prototype.resolve = function() {
 
    var diff_x = this.p1.x - this.p2.x,
        diff_y = this.p1.y - this.p2.y,
        dist = Math.sqrt(diff_x * diff_x + diff_y * diff_y),
        diff = (this.length - dist) / dist;
 
    if (dist > tear_distance) this.p1.remove_constraint(this);
 
    var px = diff_x * diff * 0.5;
    var py = diff_y * diff * 0.5;
 
    this.p1.x += px;
    this.p1.y += py;
    this.p2.x -= px;
    this.p2.y -= py;
};
 
Constraint.prototype.draw = function() {
 
    ctx.moveTo(this.p1.x, this.p1.y);
    ctx.lineTo(this.p2.x, this.p2.y);
};
 
var Cloth = function() {
 
    this.points = [];
 
    var start_x = canvas.width / 2 - cloth_width * spacing / 2;
 
    for(var y = 0; y <= cloth_height; y++) {
 
        for(var x = 0; x <= cloth_width; x++) {
 
            var p = new Point(start_x + x * spacing, start_y + y * spacing);
 
   x != 0 && p.attach(this.points[this.points.length - 1]);
            y == 0 && p.pin(p.x, p.y);
            y != 0 && p.attach(this.points[x + (y - 1) * (cloth_width + 1)])
 
            this.points.push(p);
        }
    }
};
 
Cloth.prototype.update = function() {
 
    var i = physics_accuracy;
 
    while(i--) {
        var p = this.points.length;
        while(p--) this.points[p].resolve_constraints();
    }
 
    i = this.points.length;
    while(i--) this.points[i].update(.016);
};
 
Cloth.prototype.draw = function() {
 
    ctx.beginPath();
 
    var i = cloth.points.length;
    while(i--) cloth.points[i].draw();
 
    ctx.stroke();
};
 
function update() {
 
    ctx.clearRect(0, 0, canvas.width, canvas.height);
 
    cloth.update();
    cloth.draw();
 
    requestAnimFrame(update);
}//@ sourceURL=pen.js</script>
</body></html>

13.烟花:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Canvas绘制3D烟花动画特效</title>

<style>
html,body{
	margin:0px;
	width:100%;
	height:100%;
	overflow:hidden;
	background:#000;
}

#canvas{
	width:100%;
	height:100%;
}
</style>

</head>
<body>

<canvas id="canvas"></canvas><script>
function initVars(){

	pi=Math.PI;
	ctx=canvas.getContext("2d");
	canvas.width=canvas.clientWidth;
	canvas.height=canvas.clientHeight;
	cx=canvas.width/2;
	cy=canvas.height/2;
	playerZ=-25;
	playerX=playerY=playerVX=playerVY=playerVZ=pitch=yaw=pitchV=yawV=0;
	scale=600;
	seedTimer=0;seedInterval=5,seedLife=100;gravity=.02;
	seeds=new Array();
	sparkPics=new Array();
	s="https://cantelope.org/NYE/";
	for(i=1;i<=10;++i){
		sparkPic=new Image();
		sparkPic.src=s+"spark"+i+".png";
		sparkPics.push(sparkPic);
	}
	sparks=new Array();
	pow1=new Audio(s+"pow1.ogg");
	pow2=new Audio(s+"pow2.ogg");
	pow3=new Audio(s+"pow3.ogg");
	pow4=new Audio(s+"pow4.ogg");
	frames = 0;
}

function rasterizePoint(x,y,z){

	var p,d;
	x-=playerX;
	y-=playerY;
	z-=playerZ;
	p=Math.atan2(x,z);
	d=Math.sqrt(x*x+z*z);
	x=Math.sin(p-yaw)*d;
	z=Math.cos(p-yaw)*d;
	p=Math.atan2(y,z);
	d=Math.sqrt(y*y+z*z);
	y=Math.sin(p-pitch)*d;
	z=Math.cos(p-pitch)*d;
	var rx1=-1000,ry1=1,rx2=1000,ry2=1,rx3=0,ry3=0,rx4=x,ry4=z,uc=(ry4-ry3)*(rx2-rx1)-(rx4-rx3)*(ry2-ry1);
	if(!uc) return {x:0,y:0,d:-1};
	var ua=((rx4-rx3)*(ry1-ry3)-(ry4-ry3)*(rx1-rx3))/uc;
	var ub=((rx2-rx1)*(ry1-ry3)-(ry2-ry1)*(rx1-rx3))/uc;
	if(!z)z=.000000001;
	if(ua>0&&ua<1&&ub>0&&ub<1){
		return {
			x:cx+(rx1+ua*(rx2-rx1))*scale,
			y:cy+y/z*scale,
			d:Math.sqrt(x*x+y*y+z*z)
		};
	}else{
		return {
			x:cx+(rx1+ua*(rx2-rx1))*scale,
			y:cy+y/z*scale,
			d:-1
		};
	}
}

function spawnSeed(){
	
	seed=new Object();
	seed.x=-50+Math.random()*100;
	seed.y=25;
	seed.z=-50+Math.random()*100;
	seed.vx=.1-Math.random()*.2;
	seed.vy=-1.5;//*(1+Math.random()/2);
	seed.vz=.1-Math.random()*.2;
	seed.born=frames;
	seeds.push(seed);
}

function splode(x,y,z){
	
	t=5+parseInt(Math.random()*150);
	sparkV=1+Math.random()*2.5;
	type=parseInt(Math.random()*3);
	switch(type){
		case 0:
			pic1=parseInt(Math.random()*10);
			break;
		case 1:
			pic1=parseInt(Math.random()*10);
			do{ pic2=parseInt(Math.random()*10); }while(pic2==pic1);
			break;
		case 2:
			pic1=parseInt(Math.random()*10);
			do{ pic2=parseInt(Math.random()*10); }while(pic2==pic1);
			do{ pic3=parseInt(Math.random()*10); }while(pic3==pic1 || pic3==pic2);
			break;
	}
	for(m=1;m<t;++m){
		spark=new Object();
		spark.x=x; spark.y=y; spark.z=z;
		p1=pi*2*Math.random();
		p2=pi*Math.random();
		v=sparkV*(1+Math.random()/6)
		spark.vx=Math.sin(p1)*Math.sin(p2)*v;
		spark.vz=Math.cos(p1)*Math.sin(p2)*v;
		spark.vy=Math.cos(p2)*v;
		switch(type){
			case 0: spark.img=sparkPics[pic1]; break;
			case 1:
				spark.img=sparkPics[parseInt(Math.random()*2)?pic1:pic2];
				break;
			case 2:
				switch(parseInt(Math.random()*3)){
					case 0: spark.img=sparkPics[pic1]; break;
					case 1: spark.img=sparkPics[pic2]; break;
					case 2: spark.img=sparkPics[pic3]; break;
				}
				break;
		}
		spark.radius=25+Math.random()*50;
		spark.alpha=1;
		spark.trail=new Array();
		sparks.push(spark);
	}
	switch(parseInt(Math.random()*4)){
		case 0:	pow=new Audio(s+"pow1.ogg"); break;
		case 1:	pow=new Audio(s+"pow2.ogg"); break;
		case 2:	pow=new Audio(s+"pow3.ogg"); break;
		case 3:	pow=new Audio(s+"pow4.ogg"); break;
	}
	d=Math.sqrt((x-playerX)*(x-playerX)+(y-playerY)*(y-playerY)+(z-playerZ)*(z-playerZ));
	pow.volume=1.5/(1+d/10);
	pow.play();
}

function doLogic(){
	
	if(seedTimer<frames){
		seedTimer=frames+seedInterval*Math.random()*10;
		spawnSeed();
	}
	for(i=0;i<seeds.length;++i){
		seeds[i].vy+=gravity;
		seeds[i].x+=seeds[i].vx;
		seeds[i].y+=seeds[i].vy;
		seeds[i].z+=seeds[i].vz;
		if(frames-seeds[i].born>seedLife){
			splode(seeds[i].x,seeds[i].y,seeds[i].z);
			seeds.splice(i,1);
		}
	}
	for(i=0;i<sparks.length;++i){
		if(sparks[i].alpha>0 && sparks[i].radius>5){
			sparks[i].alpha-=.01;
			sparks[i].radius/=1.02;
			sparks[i].vy+=gravity;
			point=new Object();
			point.x=sparks[i].x;
			point.y=sparks[i].y;
			point.z=sparks[i].z;
			if(sparks[i].trail.length){
				x=sparks[i].trail[sparks[i].trail.length-1].x;
				y=sparks[i].trail[sparks[i].trail.length-1].y;
				z=sparks[i].trail[sparks[i].trail.length-1].z;
				d=((point.x-x)*(point.x-x)+(point.y-y)*(point.y-y)+(point.z-z)*(point.z-z));
				if(d>9){
					sparks[i].trail.push(point);
				}
			}else{
				sparks[i].trail.push(point);
			}
			if(sparks[i].trail.length>5)sparks[i].trail.splice(0,1);				
			sparks[i].x+=sparks[i].vx;
			sparks[i].y+=sparks[i].vy;
			sparks[i].z+=sparks[i].vz;
			sparks[i].vx/=1.075;
			sparks[i].vy/=1.075;
			sparks[i].vz/=1.075;
		}else{
			sparks.splice(i,1);
		}
	}
	p=Math.atan2(playerX,playerZ);
	d=Math.sqrt(playerX*playerX+playerZ*playerZ);
	d+=Math.sin(frames/80)/1.25;
	t=Math.sin(frames/200)/40;
	playerX=Math.sin(p+t)*d;
	playerZ=Math.cos(p+t)*d;
	yaw=pi+p+t;
}

function rgb(col){
	
	var r = parseInt((.5+Math.sin(col)*.5)*16);
	var g = parseInt((.5+Math.cos(col)*.5)*16);
	var b = parseInt((.5-Math.sin(col)*.5)*16);
	return "#"+r.toString(16)+g.toString(16)+b.toString(16);
}

function draw(){
	
	ctx.clearRect(0,0,cx*2,cy*2);
	
	ctx.fillStyle="#ff8";
	for(i=-100;i<100;i+=3){
		for(j=-100;j<100;j+=4){
			x=i;z=j;y=25;
			point=rasterizePoint(x,y,z);
			if(point.d!=-1){
				size=250/(1+point.d);
				d = Math.sqrt(x * x + z * z);
				a = 0.75 - Math.pow(d / 100, 6) * 0.75;
				if(a>0){
					ctx.globalAlpha = a;
					ctx.fillRect(point.x-size/2,point.y-size/2,size,size);				
				}
			}
		}
	}
	ctx.globalAlpha=1;
	for(i=0;i<seeds.length;++i){
		point=rasterizePoint(seeds[i].x,seeds[i].y,seeds[i].z);
		if(point.d!=-1){
			size=200/(1+point.d);
			ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
		}
	}
	point1=new Object();
	for(i=0;i<sparks.length;++i){
		point=rasterizePoint(sparks[i].x,sparks[i].y,sparks[i].z);
		if(point.d!=-1){
			size=sparks[i].radius*200/(1+point.d);
			if(sparks[i].alpha<0)sparks[i].alpha=0;
			if(sparks[i].trail.length){
				point1.x=point.x;
				point1.y=point.y;
				switch(sparks[i].img){
					case sparkPics[0]:ctx.strokeStyle="#f84";break;
					case sparkPics[1]:ctx.strokeStyle="#84f";break;
					case sparkPics[2]:ctx.strokeStyle="#8ff";break;
					case sparkPics[3]:ctx.strokeStyle="#fff";break;
					case sparkPics[4]:ctx.strokeStyle="#4f8";break;
					case sparkPics[5]:ctx.strokeStyle="#f44";break;
					case sparkPics[6]:ctx.strokeStyle="#f84";break;
					case sparkPics[7]:ctx.strokeStyle="#84f";break;
					case sparkPics[8]:ctx.strokeStyle="#fff";break;
					case sparkPics[9]:ctx.strokeStyle="#44f";break;
				}
				for(j=sparks[i].trail.length-1;j>=0;--j){
					point2=rasterizePoint(sparks[i].trail[j].x,sparks[i].trail[j].y,sparks[i].trail[j].z);
					if(point2.d!=-1){
						ctx.globalAlpha=j/sparks[i].trail.length*sparks[i].alpha/2;
						ctx.beginPath();
						ctx.moveTo(point1.x,point1.y);
						ctx.lineWidth=1+sparks[i].radius*10/(sparks[i].trail.length-j)/(1+point2.d);
						ctx.lineTo(point2.x,point2.y);
						ctx.stroke();
						point1.x=point2.x;
						point1.y=point2.y;
					}
				}
			}
			ctx.globalAlpha=sparks[i].alpha;
			ctx.drawImage(sparks[i].img,point.x-size/2,point.y-size/2,size,size);
		}
	}
}

function frame(){

	if(frames>100000){
		seedTimer=0;
		frames=0;
	}
	frames++;
	draw();
	doLogic();
	requestAnimationFrame(frame);
}

window.addEventListener("resize",()=>{
	canvas.width=canvas.clientWidth;
	canvas.height=canvas.clientHeight;
	cx=canvas.width/2;
	cy=canvas.height/2;
});

initVars();
frame();
</script>

</body>
</html>

14.银河系:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Canvas全屏背景动画</title>
<style>
body {
  background: #060e1b;
  overflow: hidden;
}
.codrops-demos {
    font-size: 0.8em;
    text-align:center;
    position:absolute;
    z-index:99;
    width:96%;
}
.codrops-demos a {
    display: inline-block;
    margin: 0.35em 0.1em;
    padding: 0.5em 1.2em;
    outline: none;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    border-radius: 2px;
    font-size: 110%;
    border: 2px solid transparent;
    color:#fff;
}
.codrops-demos a:hover,
.codrops-demos a.current-demo {
    border-color: #383a3c;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
"use strict";
var canvas = document.getElementById('canvas'),
  ctx = canvas.getContext('2d'),
  w = canvas.width = window.innerWidth,
  h = canvas.height = window.innerHeight,
  hue = 217,
  stars = [],
  count = 0,
  maxStars = 1400;
var canvas2 = document.createElement('canvas'),
    ctx2 = canvas2.getContext('2d');
    canvas2.width = 100;
    canvas2.height = 100;
var half = canvas2.width/2,
    gradient2 = ctx2.createRadialGradient(half, half, 0, half, half, half);
    gradient2.addColorStop(0.025, '#fff');
    gradient2.addColorStop(0.1, 'hsl(' + hue + ', 61%, 33%)');
    gradient2.addColorStop(0.25, 'hsl(' + hue + ', 64%, 6%)');
    gradient2.addColorStop(1, 'transparent');
    ctx2.fillStyle = gradient2;
    ctx2.beginPath();
    ctx2.arc(half, half, half, 0, Math.PI * 2);
    ctx2.fill();
// End cache
function random(min, max) {
  if (arguments.length < 2) {
    max = min;
    min = 0;
  }
  if (min > max) {
    var hold = max;
    max = min;
    min = hold;
  }
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
var Star = function() {
  this.orbitRadius = random(w / 2 - 50);
  this.radius = random(100, this.orbitRadius) / 10;
  this.orbitX = w / 2;
  this.orbitY = h / 2;
  this.timePassed = random(0, maxStars);
  this.speed = random(this.orbitRadius) / 900000;
  this.alpha = random(2, 10) / 10;
  count++;
  stars[count] = this;
}
Star.prototype.draw = function() {
  var x = Math.sin(this.timePassed + 1) * this.orbitRadius + this.orbitX,
      y = Math.cos(this.timePassed) * this.orbitRadius/2 + this.orbitY,
      twinkle = random(10);
  if (twinkle === 1 && this.alpha > 0) {
    this.alpha -= 0.05;
  } else if (twinkle === 2 && this.alpha < 1) {
    this.alpha += 0.05;
  }
  ctx.globalAlpha = this.alpha;
    ctx.drawImage(canvas2, x - this.radius / 2, y - this.radius / 2, this.radius, this.radius);
  this.timePassed += this.speed;
}
for (var i = 0; i < maxStars; i++) {
  new Star();
}
function animation() {
    ctx.globalCompositeOperation = 'source-over';
    ctx.globalAlpha = 0.8;
    ctx.fillStyle = 'hsla(' + hue + ', 64%, 6%, 1)';
    ctx.fillRect(0, 0, w, h)
  ctx.globalCompositeOperation = 'lighter';
  for (var i = 1, l = stars.length; i < l; i++) {
    stars[i].draw();
  };
  window.requestAnimationFrame(animation);
}
animation();
</script>
</body>
</html>

15.乱码雨

(红色)

<!doctype html>
<html>
	<head>
		<meta charset="GB2312" />
		<title>流星雨</title>
		<meta name="keywords" content="关键词,关键字">
		<meta name="description" content="描述信息">
		<style>
			body {
				margin: 0;
				overflow: hidden;
			}
		</style>
	</head>
 
	<body>
 
		<!--
			<canvas>画布 画板 画画的本子
		-->
		<canvas width=400 height=400 style="background:#000000;" id="canvas"></canvas>
 
		<!--
			javascript
			画笔
		--> 
		<script>
					
			//获取画板
			//doccument 当前文档
			//getElement 获取一个标签
			//ById 通过Id名称的方式
			//var 声明一片空间
			//var canvas 声明一片空间的名字叫做canvas
			var canvas = document.getElementById("canvas");
			//获取画板权限 上下文
			var ctx = canvas.getContext("2d");
			//让画板的大小等于屏幕的大小
			/*
				思路:
					1.获取屏幕对象
					2.获取屏幕的尺寸
					3.屏幕的尺寸赋值给画板
			*/
			//获取屏幕对象
			var s = window.screen;
			//获取屏幕的宽度和高度
			var w = s.width;
			var h = s.height;
			//设置画板的大小
			canvas.width = w;
			canvas.height = h;
 
			//设置文字大小 
			var fontSize = 14;
			//计算一行有多少个文字 取整数 向下取整
			var clos = Math.floor(w/fontSize);
			//思考每一个字的坐标
			//创建数组把clos 个 0 (y坐标存储起来)
			var drops = [];
			var str = "qwertyuiopasdfghjklzxcvbnm";
			//往数组里面添加 clos 个 0
			for(var i = 0;i<clos;i++) {
				drops.push(0);
			}
 
			//绘制文字
			function drawString() {
				//给矩形设置填充色
				ctx.fillStyle="rgba(0,0,0,0.05)"
				//绘制一个矩形
				ctx.fillRect(0,0,w,h);
 
				//添加文字样式
				ctx.font = "600 "+fontSize+"px 微软雅黑";
				//设置文字颜色
				ctx.fillStyle = "#ff2d2d";
 
				for(var i = 0;i<clos;i++) {
					//x坐标
					var x = i*fontSize;
					//y坐标
					var y = drops[i]*fontSize;
					//设置绘制文字
					ctx.fillText(str[Math.floor(Math.random()*str.length)],x,y);
					if(y>h&&Math.random()>0.99){
						drops[i] = 0;
					}
					drops[i]++;
				}
					
			}
			//定义一个定时器,每隔30毫秒执行一次
			setInterval(drawString,30);
		</script>
	</body>
</html>
相关推荐:

纯css3流星雨_html/css_WEB-ITnose

HTML5梦幻之旅——炫丽的流星雨效果实现过程_html5教程技巧

html在图片上实现下雨效果_html/css_WEB-ITnose

(绿色)

<canvas id="canvas" style="background:black" width="620" height="340"></canvas>
<audio style="display:none; height: 0" id="bg-music" preload="auto" src="music/黑客帝国.mp3"></audio>
<style type="text/css">
body{margin: 0; padding: 0; overflow: hidden;}
</style>
<script type="text/javascript">
    
    window.onload = function(){
        //获取图形对象
        var canvas = document.getElementById("canvas");
        //获取图形的上下文
        var context = canvas.getContext("2d");
        //获取浏览器屏幕的宽度和高度
        var W = window.innerWidth;
        var H = window.innerHeight;
        //设置canvas的宽度和高度
        canvas.width = W;
        canvas.height = H;
        //每个文字的字体大小
        var fontSize = 15;
        //计算列
        var colunms = Math.floor(W /fontSize);    
        //记录每列文字的y轴坐标
        var drops = [];
        //给每一个文字初始化一个起始点的位置
        for(var i=0;i<colunms;i++){
            drops.push(0);
        }

        //运动的文字
        var str ="01abcdefghijklmnopqurstuvwxyz";
        //4:fillText(str,x,y);原理就是去更改y的坐标位置
        //绘画的函数
        function draw(){
        //让背景逐渐由透明到不透明
            context.fillStyle = "rgba(0,0,0,0.05)";
            context.fillRect(0,0,W,H);
            //给字体设置样式
            //context.font = "700 "+fontSize+"px  微软雅黑";
            context.font = fontSize + 'px arial';
            //给字体添加颜色
            context.fillStyle ="green";//随意更改字体颜色
            //写入图形中
            for(var i=0;i<colunms;i++){
                var index = Math.floor(Math.random() * str.length);
                var x = i*fontSize;
                var y = drops[i] *fontSize;
                context.fillText(str[index],x,y);
                //如果要改变时间,肯定就是改变每次他的起点
                if(y >= canvas.height && Math.random() > 0.92){
                    drops[i] = 0;
                }
                drops[i]++;
            }
        };

        function randColor(){
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb("+r+","+g+","+b+")";
        }

        draw();
        setInterval(draw,33);
    };

</script>

16.地球仪:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        body {
            background: #000;
        }
        @keyframes runing {
            0% {
                transform: rotate(23.6deg) rotateX(-23.6deg) rotateY(0deg);
            }
            100% {
                transform: rotate(23.6deg) rotateX(-23.6deg) rotateY(360deg);
            }
        }
        .big {
            position: fixed;
            top: 50%;
            left: 50%;
            /*position: relative;*/
            width: 1000px;
            height: 1000px;
            transform: translate(-50%,-55%);
            /*background: seagreen;*/
        }
        .bigbox {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 600px;
            height: 600px;
            /*background: seagreen;*/
            transform: translate(-50%,-50%);
            perspective: 1200px;
        }
        .box {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            /*background: orangered;*/
            transform-style: preserve-3d;
            animation: runing 15s linear infinite;
        }
        .box div {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            color: #fff;
            border: 1px solid #fff;
            border-radius: 50%;
        }

        .box div:nth-child(1) {

        }
        .box div:nth-child(2) {
            transform: rotateY(22.5deg);
        }
        .box div:nth-child(3) {
            transform: rotateY(45deg);
        }
        .box div:nth-child(4) {
            transform: rotateY(67.5deg);
        }
        .box div:nth-child(5) {
            transform: rotateY(90deg);
        }
        .box div:nth-child(6) {
            transform: rotateY(112.5deg);
        }
        .box div:nth-child(7) {
            transform: rotateY(135deg);
        }
        .box div:nth-child(8) {
            transform: rotateY(157.5deg);
        }
        .box div:nth-child(9) {
            transform: translateY(-300px) rotateX(90deg) scale(0);
        }
        .box div:nth-child(10) {
            transform: translateY(-225px) rotateX(90deg) scale(.66);
        }
        .box div:nth-child(11) {
            transform: translateY(-150px) rotateX(90deg) scale(.865);
        }
        .box div:nth-child(12) {
            transform: translateY(-75px) rotateX(90deg) scale(.97);
        }
        .box div:nth-child(13) {
            transform: translateY(0) rotateX(90deg) scale(1);
        }
        .box div:nth-child(14) {
            transform: translateY(75px) rotateX(90deg) scale(.97);
        }
        .box div:nth-child(15) {
            transform: translateY(150px) rotateX(90deg) scale(.865);
        }
        .box div:nth-child(16) {
            transform: translateY(225px) rotateX(90deg) scale(.66);
        }
        .box div:nth-child(17) {
            transform: translateY(300px) rotateX(90deg) scale(0);
        }
        .but {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 3px;
            height: 680px;
            background: #fff;
            border-radius: 0;
            transform: translate(-50%,-50%) rotate(23.6deg);
        }
        .fix {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 680px;
            height: 680px;
            z-index: 99;
            /*background: seagreen;*/
            /*opacity: .5;*/
            border-radius:50%;
            border-top: 20px solid #fff;
            border-right: 20px solid #fff;
            border-left: 20px solid transparent;
            border-bottom: 20px solid transparent;
            transform: translate(-52%,-51%) rotate(68.6deg);
        }
        .foot {
            position: absolute;
            top: 850px;
            left: 50%;
            transform: translate(-50%,0);
            z-index: 3;
            width: 30px;
            height: 60px;
            background: #fff;
        }
        .footer {
            position: absolute;
            top: 765px;
            left: 50%;
            width:300px;
            height:300px;
            border:solid 1px black;
            background: #fff;
            border-radius: 50%;
            transform: translate(-50%,0) rotateX(80deg);
        }
        .footer:after{
            content: '';
            display:inline-block;
            width:300px;
            height: 320px;
            position:relative;
            opacity: 0.8;
            background: #fff;
            top:50%;
            left:-0.5px;
            border-left: 1px solid #000;
            border-right: 1px solid #000;
            border-bottom: 1px solid #000;
            border-bottom-left-radius: 45%;
            border-bottom-right-radius: 45%;
        }
    </style>
</head>
<body>
    <div class="big">
        <div class="bigbox">
            <div class="box">

                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </div>
            <div class="but"></div>
        </div>
        <div class="fix"></div>
        <div class="foot"></div>
        <div class="footer"></div>
    </div>
</body>
</html>

17.爱心(自己输入名字(默认名字叫蔡徐坤))

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> Love </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
  html, body {
  height: 100%;
  padding: 0;
  margin: 0;
  background: #000;
}
canvas {
  position: absolute;
  width: 100%;
  height: 100%;
}
  </style>
  <style type="text/css">
	div{auto;
	  color: #ea80b0;
	  font-size: 5rem;
	  font-family: STXingkai;
	  text-shadow: 0 0 10px plum,0 0 20px plum,0 0 30px plum,0 0 40px plum;
	  }
	  .box{
		  position: absolute;
		  top: 50%;
		  left: 45%;
		  -webkit-transform: translateY(-50%);
		  -ms-transform: translateY(-50%);
		  -o-transform: translateY(-50%);
		  transform: translateY(-50%);
	  }
  </style>
 </HEAD>

 <BODY>
  <canvas id="pinkboard"></canvas>
  <script>
  /*
 * Settings
 */
var settings = {
  particles: {
    length:   500, // maximum amount of particles
    duration:   2, // particle duration in sec
    velocity: 100, // particle velocity in pixels/sec
    effect: -0.75, // play with this for a nice effect
    size:      30, // particle size in pixels
  },
};

/*
 * RequestAnimationFrame polyfill by Erik M?ller
 */
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());

/*
 * Point class
 */
var Point = (function() {
  function Point(x, y) {
    this.x = (typeof x !== 'undefined') ? x : 0;
    this.y = (typeof y !== 'undefined') ? y : 0;
  }
  Point.prototype.clone = function() {
    return new Point(this.x, this.y);
  };
  Point.prototype.length = function(length) {
    if (typeof length == 'undefined')
      return Math.sqrt(this.x * this.x + this.y * this.y);
    this.normalize();
    this.x *= length;
    this.y *= length;
    return this;
  };
  Point.prototype.normalize = function() {
    var length = this.length();
    this.x /= length;
    this.y /= length;
    return this;
  };
  return Point;
})();

/*
 * Particle class
 */
var Particle = (function() {
  function Particle() {
    this.position = new Point();
    this.velocity = new Point();
    this.acceleration = new Point();
    this.age = 0;
  }
  Particle.prototype.initialize = function(x, y, dx, dy) {
    this.position.x = x;
    this.position.y = y;
    this.velocity.x = dx;
    this.velocity.y = dy;
    this.acceleration.x = dx * settings.particles.effect;
    this.acceleration.y = dy * settings.particles.effect;
    this.age = 0;
  };
  Particle.prototype.update = function(deltaTime) {
    this.position.x += this.velocity.x * deltaTime;
    this.position.y += this.velocity.y * deltaTime;
    this.velocity.x += this.acceleration.x * deltaTime;
    this.velocity.y += this.acceleration.y * deltaTime;
    this.age += deltaTime;
  };
  Particle.prototype.draw = function(context, image) {
    function ease(t) {
      return (--t) * t * t + 1;
    }
    var size = image.width * ease(this.age / settings.particles.duration);
    context.globalAlpha = 1 - this.age / settings.particles.duration;
    context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
  };
  return Particle;
})();

/*
 * ParticlePool class
 */
var ParticlePool = (function() {
  var particles,
      firstActive = 0,
      firstFree   = 0,
      duration    = settings.particles.duration;
  
  function ParticlePool(length) {
    // create and populate particle pool
    particles = new Array(length);
    for (var i = 0; i < particles.length; i++)
      particles[i] = new Particle();
  }
  ParticlePool.prototype.add = function(x, y, dx, dy) {
    particles[firstFree].initialize(x, y, dx, dy);
    
    // handle circular queue
    firstFree++;
    if (firstFree   == particles.length) firstFree   = 0;
    if (firstActive == firstFree       ) firstActive++;
    if (firstActive == particles.length) firstActive = 0;
  };
  ParticlePool.prototype.update = function(deltaTime) {
    var i;
    
    // update active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].update(deltaTime);
      for (i = 0; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    
    // remove inactive particles
    while (particles[firstActive].age >= duration && firstActive != firstFree) {
      firstActive++;
      if (firstActive == particles.length) firstActive = 0;
    }
    
    
  };
  ParticlePool.prototype.draw = function(context, image) {
    // draw active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].draw(context, image);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].draw(context, image);
      for (i = 0; i < firstFree; i++)
        particles[i].draw(context, image);
    }
  };
  return ParticlePool;
})();

/*
 * Putting it all together
 */
(function(canvas) {
  var context = canvas.getContext('2d'),
      particles = new ParticlePool(settings.particles.length),
      particleRate = settings.particles.length / settings.particles.duration, // particles/sec
      time;
  
  // get point on heart with -PI <= t <= PI
  function pointOnHeart(t) {
    return new Point(
      160 * Math.pow(Math.sin(t), 3),
      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
    );
  }
  
  // creating the particle image using a dummy canvas
  var image = (function() {
    var canvas  = document.createElement('canvas'),
        context = canvas.getContext('2d');
    canvas.width  = settings.particles.size;
    canvas.height = settings.particles.size;
    // helper function to create the path
    function to(t) {
      var point = pointOnHeart(t);
      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;
      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
      return point;
    }
    // create the path
    context.beginPath();
    var t = -Math.PI;
    var point = to(t);
    context.moveTo(point.x, point.y);
    while (t < Math.PI) {
      t += 0.01; // baby steps!
      point = to(t);
      context.lineTo(point.x, point.y);
    }
    context.closePath();
    // create the fill
    context.fillStyle = '#ea80b0';
    context.fill();
    // create the image
    var image = new Image();
    image.src = canvas.toDataURL();
    return image;
  })();
  
  // render that thing!
  function render() {
    // next animation frame
    requestAnimationFrame(render);
    
    // update time
    var newTime   = new Date().getTime() / 1000,
        deltaTime = newTime - (time || newTime);
    time = newTime;
    
    // clear canvas
    context.clearRect(0, 0, canvas.width, canvas.height);
    
    // create new particles
    var amount = particleRate * deltaTime;
    for (var i = 0; i < amount; i++) {
      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
      var dir = pos.clone().length(settings.particles.velocity);
      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
    }
    
    // update and draw particles
    particles.update(deltaTime);
    particles.draw(context, image);
  }
  
  // handle (re-)sizing of the canvas
  function onResize() {
    canvas.width  = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
  }
  window.onresize = onResize;
  
  // delay rendering bootstrap
  setTimeout(function() {
    onResize();
    render();
  }, 10);
})(document.getElementById('pinkboard'));
  </script>
  <div class="box">蔡徐坤</div>
 </BODY>
</HTML>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282


不加名字的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> Love </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
  html, body {
  height: 100%;
  padding: 0;
  margin: 0;
  background: #000;
}
canvas {
  position: absolute;
  width: 100%;
  height: 100%;
}
  </style>
 </HEAD>

 <BODY>
  <canvas id="pinkboard"></canvas>
  <script>
  /*
 * Settings
 */
var settings = {
  particles: {
    length:   500, // maximum amount of particles
    duration:   2, // particle duration in sec
    velocity: 100, // particle velocity in pixels/sec
    effect: -0.75, // play with this for a nice effect
    size:      30, // particle size in pixels
  },
};

/*
 * RequestAnimationFrame polyfill by Erik M?ller
 */
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());

/*
 * Point class
 */
var Point = (function() {
  function Point(x, y) {
    this.x = (typeof x !== 'undefined') ? x : 0;
    this.y = (typeof y !== 'undefined') ? y : 0;
  }
  Point.prototype.clone = function() {
    return new Point(this.x, this.y);
  };
  Point.prototype.length = function(length) {
    if (typeof length == 'undefined')
      return Math.sqrt(this.x * this.x + this.y * this.y);
    this.normalize();
    this.x *= length;
    this.y *= length;
    return this;
  };
  Point.prototype.normalize = function() {
    var length = this.length();
    this.x /= length;
    this.y /= length;
    return this;
  };
  return Point;
})();

/*
 * Particle class
 */
var Particle = (function() {
  function Particle() {
    this.position = new Point();
    this.velocity = new Point();
    this.acceleration = new Point();
    this.age = 0;
  }
  Particle.prototype.initialize = function(x, y, dx, dy) {
    this.position.x = x;
    this.position.y = y;
    this.velocity.x = dx;
    this.velocity.y = dy;
    this.acceleration.x = dx * settings.particles.effect;
    this.acceleration.y = dy * settings.particles.effect;
    this.age = 0;
  };
  Particle.prototype.update = function(deltaTime) {
    this.position.x += this.velocity.x * deltaTime;
    this.position.y += this.velocity.y * deltaTime;
    this.velocity.x += this.acceleration.x * deltaTime;
    this.velocity.y += this.acceleration.y * deltaTime;
    this.age += deltaTime;
  };
  Particle.prototype.draw = function(context, image) {
    function ease(t) {
      return (--t) * t * t + 1;
    }
    var size = image.width * ease(this.age / settings.particles.duration);
    context.globalAlpha = 1 - this.age / settings.particles.duration;
    context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
  };
  return Particle;
})();

/*
 * ParticlePool class
 */
var ParticlePool = (function() {
  var particles,
      firstActive = 0,
      firstFree   = 0,
      duration    = settings.particles.duration;
  
  function ParticlePool(length) {
    // create and populate particle pool
    particles = new Array(length);
    for (var i = 0; i < particles.length; i++)
      particles[i] = new Particle();
  }
  ParticlePool.prototype.add = function(x, y, dx, dy) {
    particles[firstFree].initialize(x, y, dx, dy);
    
    // handle circular queue
    firstFree++;
    if (firstFree   == particles.length) firstFree   = 0;
    if (firstActive == firstFree       ) firstActive++;
    if (firstActive == particles.length) firstActive = 0;
  };
  ParticlePool.prototype.update = function(deltaTime) {
    var i;
    
    // update active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].update(deltaTime);
      for (i = 0; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    
    // remove inactive particles
    while (particles[firstActive].age >= duration && firstActive != firstFree) {
      firstActive++;
      if (firstActive == particles.length) firstActive = 0;
    }
    
    
  };
  ParticlePool.prototype.draw = function(context, image) {
    // draw active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].draw(context, image);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].draw(context, image);
      for (i = 0; i < firstFree; i++)
        particles[i].draw(context, image);
    }
  };
  return ParticlePool;
})();

/*
 * Putting it all together
 */
(function(canvas) {
  var context = canvas.getContext('2d'),
      particles = new ParticlePool(settings.particles.length),
      particleRate = settings.particles.length / settings.particles.duration, // particles/sec
      time;
  
  // get point on heart with -PI <= t <= PI
  function pointOnHeart(t) {
    return new Point(
      160 * Math.pow(Math.sin(t), 3),
      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
    );
  }
  
  // creating the particle image using a dummy canvas
  var image = (function() {
    var canvas  = document.createElement('canvas'),
        context = canvas.getContext('2d');
    canvas.width  = settings.particles.size;
    canvas.height = settings.particles.size;
    // helper function to create the path
    function to(t) {
      var point = pointOnHeart(t);
      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;
      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
      return point;
    }
    // create the path
    context.beginPath();
    var t = -Math.PI;
    var point = to(t);
    context.moveTo(point.x, point.y);
    while (t < Math.PI) {
      t += 0.01; // baby steps!
      point = to(t);
      context.lineTo(point.x, point.y);
    }
    context.closePath();
    // create the fill
    context.fillStyle = '#ea80b0';
    context.fill();
    // create the image
    var image = new Image();
    image.src = canvas.toDataURL();
    return image;
  })();
  
  // render that thing!
  function render() {
    // next animation frame
    requestAnimationFrame(render);
    
    // update time
    var newTime   = new Date().getTime() / 1000,
        deltaTime = newTime - (time || newTime);
    time = newTime;
    
    // clear canvas
    context.clearRect(0, 0, canvas.width, canvas.height);
    
    // create new particles
    var amount = particleRate * deltaTime;
    for (var i = 0; i < amount; i++) {
      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
      var dir = pos.clone().length(settings.particles.velocity);
      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
    }
    
    // update and draw particles
    particles.update(deltaTime);
    particles.draw(context, image);
  }
  
  // handle (re-)sizing of the canvas
  function onResize() {
    canvas.width  = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
  }
  window.onresize = onResize;
  
  // delay rendering bootstrap
  setTimeout(function() {
    onResize();
    render();
  }, 10);
})(document.getElementById('pinkboard'));
  </script>
 </BODY>
</HTML>

18.小球下楼梯:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <!-- 4个board -->
        <div id="board1" style="position: absolute; width:80px; height:10px; left:420px; 
        top:555px; background-color: cadetblue;"></div>
        <div id="board2" style="position: absolute; width:80px; height:10px; left:520px; 
        top:555px; background-color: cadetblue;"></div>
        <div id="board3" style="position: absolute; width:80px; height:10px; left:620px; 
        top:555px; background-color: cadetblue;"></div>
        <div id="board4" style="position: absolute; width:80px; height:10px; left:720px; 
        top:555px; background-color: cadetblue;"></div>
        <!-- 小球 -->
        <div id="ball" class="circle" style="width:20px; 
        height:20px; background-color:crimson; border-radius: 50%; position:absolute; 
        left:600px; top:100px"></div>
        <!-- 框 -->
        <div id="box" style="border: 5px solid #555555; width:400px; height:550px"></div>
        <!-- 分数 过的board越多,分数越高 -->
        <div id="score" style="width:200px; height:10px; position:absolute; left:900px; 
            font-family:'隶书'; font-size: 30px;">分数:0</div>
        <!-- 游戏结束 -->
        <div id="gg" style="width:200px; height:10px; position:absolute; left:550px; top:200px;
        font-family:'隶书'; font-size: 30px; display: none;">游戏结束</div>
        <script>
            // 设置box的样式
            var box = document.getElementById("box");
            box.style.position = "absolute";
            box.style.left = "400px";
            // 设置board的样式
            var board1 = document.getElementById("board1");
            var board2 = document.getElementById("board2");
            var board3 = document.getElementById("board3");
            var board4 = document.getElementById("board4");
            // 声音
            var shengyin = new Audio();
            shengyin.src = "声音2.mp3";
            shengyinFlag = 0; // 用来表示小球在第几块board上
            // 键盘事件函数
            var ball = document.getElementById("ball");
            document.onkeydown = f;
            function f(e){
                var e = e || window.event;
                switch(e.keyCode){
                    case 37:
                        // 按下左键,小球左移,但不要超过左边框
                        if(ball.offsetLeft>=box.offsetLeft + 10)
                            ball.style.left = ball.offsetLeft - 8 + "px";
                        break;
                    case 39:
                        // 按下右键,小球右移,但不要超过由边框
                        if(ball.offsetLeft<=box.offsetLeft+box.offsetWidth-ball.offsetWidth-10)
                            ball.style.left = ball.offsetLeft + 8 + "px";
                        break;
                    case 32:
                        
                }
            }
            // 定义一个分数变量
            var fenshu = 0;
            // 定义一个函数,移动给定的一个board
            function moveBoard(board)
            {
                var t1 = board.offsetTop;
                if(t1<=0)
                {
                    // 如果board移到最上面了,就随机换个水平位置,再移到最下面
                    t2 = Math.floor(Math.random() * (720- 420) + 420);
                    board.style.left = t2 + "px";
                    board.style.top = "555px";
                    fenshu += 1; //分数增加1
                    document.getElementById("score").innerHTML = "分数:" + fenshu;
                }
                    // 
                else
                    board.style.top = board.offsetTop - 1 + "px";
            }
            // 定义小球的速度变量
            var startSpeed = 1;
            var ballSpeed =startSpeed;
            // step函数是游戏界面的单位变化函数
            function step()
            {
                // board直接上下隔得太近,就逐个移动,否则,同时移动
                var t1 = Math.abs(board1.offsetTop - board2.offsetTop);
                var t2 = Math.abs(board2.offsetTop - board3.offsetTop);
                var t3 = Math.abs(board3.offsetTop - board4.offsetTop);
                // 定义一个board之间的间隔距离
                var t4 = 140;
                if(t1<t4)
                {
                    moveBoard(board1);
                }
                else if(t2<t4)
                {
                    moveBoard(board1);
                    moveBoard(board2);
                }
                else if(t3<t4)
                {
                    moveBoard(board1);
                    moveBoard(board2);
                    moveBoard(board3);
                }
                else
                {
                    moveBoard(board1);
                    moveBoard(board2);
                    moveBoard(board3);
                    moveBoard(board4);
                }
                // 定义小球的垂直移动规则,1、向下匀加速运动,2、如果碰到board就被board持续抬上去,
                // 直到按左右键离开了该board

                // 如果小球的纵坐标等于某个board的纵坐标,就被抬起
                var t5 = Math.abs(ball.offsetTop - board1.offsetTop);
                var t6 = Math.abs(ball.offsetTop - board2.offsetTop);
                var t7 = Math.abs(ball.offsetTop - board3.offsetTop);
                var t8 = Math.abs(ball.offsetTop - board4.offsetTop);
                if(t5<=ball.offsetHeight && t5>0 && ball.offsetLeft>=board1.offsetLeft-ball.offsetWidth && ball.offsetLeft<=board1.offsetLeft+board1.offsetWidth)
                {
                    ball.style.top = board1.offsetTop - ball.offsetHeight + "px";
                    ballSpeed = startSpeed;
                    if(shengyinFlag != 1)
                    {
                        shengyin.play();
                        shengyinFlag = 1;
                    }
                }
                else if(t6<=ball.offsetHeight && t6>0 && ball.offsetLeft>=board2.offsetLeft-ball.offsetWidth && ball.offsetLeft<=board2.offsetLeft+board2.offsetWidth)
                {
                    ball.style.top = board2.offsetTop - ball.offsetHeight + "px";
                    ballSpeed = startSpeed;
                    if(shengyinFlag != 2)
                    {
                        shengyin.play();
                        shengyinFlag = 2;
                    }
                }
                else if(t7<=ball.offsetHeight && t7>0 && ball.offsetLeft>=board3.offsetLeft-ball.offsetWidth && ball.offsetLeft<=board3.offsetLeft+board3.offsetWidth)
                {
                    ball.style.top = board3.offsetTop - ball.offsetHeight + "px";
                    ballSpeed = startSpeed;
                    if(shengyinFlag != 3)
                    {
                        shengyin.play();
                        shengyinFlag = 3;
                    }
                }
                else if(t8<=ball.offsetHeight && t8>0 && ball.offsetLeft>=board4.offsetLeft-ball.offsetWidth && ball.offsetLeft<=board4.offsetLeft+board4.offsetWidth)
                {
                    ball.style.top = board4.offsetTop - ball.offsetHeight + "px";
                    ballSpeed = startSpeed;
                    if(shengyinFlag != 4)
                    {   
                        shengyin.play();
                        shengyinFlag = 4;
                    }
                }
                else
                {
                    ballSpeed = ballSpeed + 0.01; // 数字相当于加速度
                    ball.style.top = ball.offsetTop + ballSpeed + "px";
                }
                // ballSpeed = ballSpeed + 0.01; // 数字相当于加速度
                // ball.style.top = ball.offsetTop + ballSpeed + "px";
                
                // 如果小球跑出来box,就结束游戏
                if(ball.offsetTop==0 || ball.offsetTop>=box.offsetTop+box.offsetHeight)
                {
                    clearInterval(gameover);
                    ball.style.display = 'none';
                    board1.style.display = 'none';
                    board2.style.display = 'none';
                    board3.style.display = 'none';
                    board4.style.display = 'none';
                    var gg = document.getElementById("gg"); //显示游戏结束
                    gg.style.display = 'block';
                }
            }

            var gameover = setInterval("step();", 8);
        </script>
    </body>
</html>

想看更多代码,去我的主页。

记得点赞呦!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值