<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>简单点击游戏</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 0; padding: 0; background-color: #f0f0f0; } #game-container { display: flex; justify-content: center; align-items: center; height: 100vh; } #click-button { padding: 20px 40px; font-size: 24px; background-color: #3498db; border: none; border-radius: 8px; color: white; cursor: pointer; transition: background-color 0.3s; } #click-button:hover { background-color: #2980b9; } </style> </head> <body> <div id="game-container"> <button id="click-button">点击开始游戏</button> </div> <script> const clickButton = document.getElementById("click-button"); let score = 0; clickButton.addEventListener("click", () => { score++; clickButton.textContent = `得分:${score}`; }); </script> </body> </html>
一个简单的网页游戏的示例,你可以基于这个示例进行修改和扩展,创建属于自己的简单网页游戏。
最新推荐文章于 2024-07-21 19:42:40 发布