该gist收集有趣的H5代码。
Last active
November 28, 2017 01:22
-
-
Save lihsai0/5ba9ff6d568d035f6000aa15269e7e6b to your computer and use it in GitHub Desktop.
[Little H5] some interesting h5 codes #H5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
--> | |
<title>Matrix</title> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
background: black; | |
} | |
canvas { | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<canvas id="c"></canvas> | |
<script> | |
var c = document.getElementById("c"); | |
var ctx = c.getContext("2d"); | |
c.height = window.innerHeight; | |
c.width = window.innerWidth; | |
var matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%"; | |
matrix = matrix.split(""); | |
var font_size = 15; | |
var columns = c.width / font_size; | |
var drops = []; | |
for (var x = 0; x < columns; x++) | |
drops[x] = 1; | |
function draw() { | |
ctx.fillStyle = "rgba(0, 0, 0, 0.04)"; | |
ctx.fillRect(0, 0, c.width, c.height); | |
ctx.fillStyle = "#3F3"; | |
ctx.font = font_size + "px arial"; | |
for (var i = 0; i < drops.length; i++) { | |
var text = matrix[Math.floor(Math.random() * matrix.length)]; | |
ctx.fillText(text, i * font_size, drops[i] * font_size); | |
if (drops[i] * font_size > c.height && Math.random() > 0.975) | |
drops[i] = 0; | |
drops[i]++; | |
} | |
} | |
setInterval(draw, 35); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
--> | |
<title>Snake</title> | |
</head> | |
<body> | |
<canvas id="can" width="400" height="400" style="background: Black"></canvas> | |
<script> | |
var sn = [42, 41], dz = 43, fx = 1, n, ctx = document.getElementById("can").getContext("2d"); | |
function draw(t, c) { | |
ctx.fillStyle = c; | |
ctx.fillRect(t % 20 * 20 + 1, ~~(t / 20) * 20 + 1, 18, 18); | |
} | |
document.onkeydown = function (e) { | |
fx = sn[1] - sn[0] == (n = [-1, -20, 1, 20][(e || event).keyCode - 37] || fx) ? fx : n | |
}; | |
!function () { | |
sn.unshift(n = sn[0] + fx); | |
if (sn.indexOf(n, 1) > 0 || n < 0 || n > 399 || fx == 1 && n % 20 == 0 || fx == -1 && n % 20 == 19) | |
return alert("GAME OVER"); | |
draw(n, "Lime"); | |
if (n == dz) { | |
while (sn.indexOf(dz = ~~(Math.random() * 400)) >= 0); | |
draw(dz, "Yellow"); | |
} else | |
draw(sn.pop(), "Black"); | |
setTimeout(arguments.callee, 130); | |
}(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment