<!DOCTYPE html> <html> <head> <title>Math Board</title> <link rel="stylesheet" type="text/css" href="./style.css" /> <meta charset="utf-8" /> <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0" /> --> <script type="text/javascript" src="./src/code.js" defer></script> <!-- MathJax --> <script id="MathJax-script" type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async></script> </head> <body> <div id="env"> <canvas id="painting-area"></canvas> </div> <div id="bar"> <div id="paint"> <button onclick="changeTool(0)">文本框</button> <button onclick="changeTool(1)">画笔</button> <button onclick="changeTool(2)">橡皮擦</button> </div> <div id="text"> <form name="form" onsubmit="return false;"> <textarea id="input" autofocus></textarea> <button id="button" onclick="createBox();">▷</button> </form> </div> </div> </body> </html>
时间: 2023-08-14 12:55:22 浏览: 192
这是一个简单的 HTML 页面,其中包含一个数学白板的功能。页面上有一个绘画区域和一个工具栏。工具栏上有三个按钮,分别用于选择文本框、画笔和橡皮擦工具。在文本框中输入内容后,点击"▷"按钮可以创建一个文本框显示输入的内容。这个页面还引用了一些外部的 CSS 和 JavaScript 文件,用于样式和功能的实现。
相关问题
<!DOCTYPE html> <html> <head> <title>Math Board</title> <link rel="stylesheet" type="text/css" href="./style.css" /> <meta charset="utf-8" /> <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0" /> --> <script type="text/javascript" src="./src/code.js" defer></script> <!-- MathJax --> <script id="MathJax-script" type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async></script> </head> <body> <div id="env"> <canvas id="painting-area"></canvas> </div> <div id="bar"> <div id="paint"> <button onclick="changeTool(0)">文本框</button> <button onclick="changeTool(1)">画笔</button> <button onclick="changeTool(2)">橡皮擦</button> </div> <div id="text"> <form name="form" onsubmit="return false;"> <textarea id="input" autofocus></textarea> <button id="button" onclick="createBox();">▷</button> </form> </div> </div> </body> </html>
这是一个HTML页面的代码,它创建了一个名为"Math Board"的数学白板。这个页面使用了一个样式表文件“style.css”,并引入了一个JavaScript文件“code.js”来处理交互和绘图功能。此外,还引入了MathJax库来支持数学公式的渲染。
页面中有两个主要的区域:“env”和“bar”。在“env”区域中,有一个用于绘图的画布元素“painting-area”。在“bar”区域中,有一个工具栏和一个文本框,用于选择绘图工具和输入文本内容。
你可以根据需要修改HTML、CSS和JavaScript代码来自定义和扩展这个数学白板的功能。
html5 css js2048
2048是一款非常流行的数字益智游戏,可以使用HTML、CSS和JavaScript来实现。以下是一个简单的HTML、CSS和JavaScript实现2048的示例:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>2048</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header">
<h1>2048</h1>
<div class="score">0</div>
</div>
<div class="game-container">
<div class="game-board"></div>
</div>
<div class="footer">
<p>Use arrow keys to move the tiles. When two tiles with the same number touch, they merge into one!</p>
</div>
</div>
<script src="game.js"></script>
</body>
</html>
```
CSS代码:
```css
.container {
width: 500px;
margin: 0 auto;
text-align: center;
}
.header {
background-color: #eee4da;
padding: 20px;
border-radius: 5px 5px 0 0;
}
.header h1 {
margin: 0;
font-size: 60px;
color: #776e65;
}
.score {
font-size: 30px;
color: #776e65;
}
.game-container {
background-color: #bbada0;
padding: 20px;
border-radius: 0 0 5px 5px;
}
.game-board {
width: 400px;
height: 400px;
margin: 0 auto;
background-color: #cdc1b4;
position: relative;
}
.tile {
width: 90px;
height: 90px;
background-color: #eee4da;
position: absolute;
border-radius: 5px;
font-size: 40px;
font-weight: bold;
text-align: center;
line-height: 90px;
transition: all 0.1s ease-in-out;
}
.tile.new {
background-color: #eee4da;
color: #776e65;
}
.tile.merged {
background-color: #edc22e;
color: #f9f6f2;
}
.tile-2 {
top: 0;
left: 0;
}
.tile-4 {
top: 0;
right: 0;
}
.tile-8 {
top: 100px;
left: 0;
}
.tile-16 {
top: 100px;
right: 0;
}
.tile-32 {
top: 200px;
left: 0;
}
.tile-64 {
top: 200px;
right: 0;
}
.tile-128 {
top: 300px;
left: 0;
}
.tile-256 {
top: 300px;
right: 0;
}
.tile-512 {
top: 400px;
left: 0;
}
.tile-1024 {
top: 400px;
right: 0;
}
.tile-2048 {
top: 500px;
left: 0;
right: 0;
margin: 0 auto;
}
```
JavaScript代码:
```javascript
var board = [];
var score = 0;
var hasConflicted = [];
$(document).ready(function() {
newgame();
});
function newgame() {
// 初始化棋盘格
init();
// 在随机两个格子生成数字
generateOneNumber();
generateOneNumber();
}
function init() {
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 4; j++) {
var gridCell = $("#grid-cell-" + i + "-" + j);
gridCell.css("top", getPosTop(i, j));
gridCell.css("left", getPosLeft(i, j));
}
}
for (var i = 0; i < 4; i++) {
board[i] = [];
hasConflicted[i] = [];
for (var j = 0; j < 4; j++) {
board[i][j] = 0;
hasConflicted[i][j] = false;
}
}
updateBoardView();
score = 0;
updateScore(score);
}
function updateBoardView() {
$(".number-cell").remove();
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 4; j++) {
$(".game-board").append('<div class="number-cell" id="number-cell-' + i + '-' + j + '"></div>');
var theNumberCell = $('#number-cell-' + i + '-' + j);
if (board[i][j] == 0) {
theNumberCell.css("width", "0px");
theNumberCell.css("height", "0px");
theNumberCell.css("top", getPosTop(i, j) + 50);
theNumberCell.css("left", getPosLeft(i, j) + 50);
} else {
theNumberCell.css("width", "100px");
theNumberCell.css("height", "100px");
theNumberCell.css("top", getPosTop(i, j));
theNumberCell.css("left", getPosLeft(i, j));
theNumberCell.css("background-color", getNumberBackgroundColor(board[i][j]));
theNumberCell.css("color", getNumberColor(board[i][j]));
theNumberCell.text(board[i][j]);
}
hasConflicted[i][j] = false;
}
}
$(".number-cell").css("line-height", "100px");
$(".number-cell").css("font-size", "60px");
}
function generateOneNumber() {
if (nospace(board)) {
return false;
}
// 随机一个位置
var randx = parseInt(Math.floor(Math.random() * 4));
var randy = parseInt(Math.floor(Math.random() * 4));
while (true) {
if (board[randx][randy] == 0) {
break;
}
randx = parseInt(Math.floor(Math.random() * 4));
randy = parseInt(Math.floor(Math.random() * 4));
}
// 随机一个数字
var randNumber = Math.random() < 0.5 ? 2 : 4;
// 在随机位置显示随机数字
board[randx][randy] = randNumber;
showNumberWithAnimation(randx, randy, randNumber);
return true;
}
$(document).keydown(function(event) {
switch (event.keyCode) {
case 37: // left
event.preventDefault();
if (moveLeft()) {
setTimeout("generateOneNumber()", 210);
setTimeout("isgameover()", 300);
}
break;
case 38: // up
event.preventDefault();
if (moveUp()) {
setTimeout("generateOneNumber()", 210);
setTimeout("isgameover()", 300);
}
break;
case 39: // right
event.preventDefault();
if (moveRight()) {
setTimeout("generateOneNumber()", 210);
setTimeout("isgameover()", 300);
}
break;
case 40: // down
event.preventDefault();
if (moveDown()) {
setTimeout("generateOneNumber()", 210);
setTimeout("isgameover()", 300);
}
break;
default:
break;
}
});
function isgameover() {
if (nospace(board) && nomove(board)) {
gameover();
}
}
function gameover() {
alert("game over!");
}
function moveLeft() {
if (!canMoveLeft(board)) {
return false;
}
for (var i = 0; i < 4; i++) {
for (var j = 1; j < 4; j++) {
if (board[i][j] != 0) {
for (var k = 0; k < j; k++) {
if (board[i][k] == 0 && noBlockHorizontal(i, k, j, board)) {
// move
showMoveAnimation(i, j, i, k);
board[i][k] = board[i][j];
board[i][j] = 0;
continue;
} else if (board[i][k] == board[i][j] && noBlockHorizontal(i, k, j, board) && !hasConflicted[i][k]) {
// move
showMoveAnimation(i, j, i, k);
// add
board[i][k] += board[i][j];
board[i][j] = 0;
// add score
score += board[i][k];
updateScore(score);
hasConflicted[i][k] = true;
continue;
}
}
}
}
}
setTimeout("updateBoardView()", 200);
return true;
}
function moveRight() {
if (!canMoveRight(board)) {
return false;
}
for (var i = 0; i < 4; i++) {
for (var j = 2; j >= 0; j--) {
if (board[i][j] != 0) {
for (var k = 3; k > j; k--) {
if (board[i][k] == 0 && noBlockHorizontal(i, j, k, board)) {
// move
showMoveAnimation(i, j, i, k);
board[i][k] = board[i][j];
board[i][j] = 0;
continue;
} else if (board[i][k] == board[i][j] && noBlockHorizontal(i, j, k, board) && !hasConflicted[i][k]) {
// move
showMoveAnimation(i, j, i, k);
// add
board[i][k] += board[i][j];
board[i][j] = 0;
// add score
score += board[i][k];
updateScore(score);
hasConflicted[i][k] = true;
continue;
}
}
}
}
}
setTimeout("updateBoardView()", 200
阅读全文