html+css+js气球消除小游戏

气球消除小游戏 消除15个就成功 源码在图片后 点赞加关注,谢谢 左上角的数字显示消除气球的数量 定时随机生成气球 🎈🎈🎈

图片

源代码

<!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 {

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

background-color: #f0f0f0;

margin: 0;

font-family: Arial, sans-serif;

}

#score {

position: absolute;

top: 10px;

left: 10px;

font-size: 2rem;

}

.balloon {

width: 160px; /* 调整宽度以匹配高度,使气球更圆 */

height: 160px; /* 保持高度不变 */

border-radius: 50%; /* 调整为50%,使气球主体更圆 */

background: linear-gradient(#ffdad6, #ff8080);

position: absolute;

cursor: pointer;

}

.balloon:after {

content: "";

width: 4px;

height: 40px;

background-color: darkgray;

position: absolute;

bottom: -40px;

left: calc(50% - 2px);

}

</style>

</head>

<body>

<div id="score">0</div>

<script>

let score = 0;

const scoreElement = document.getElementById('score');

const colors = "#ff8080", "#80ff80", "#8080ff", "#ffff80", "#80ffff";

function createBalloon() {

const balloon = document.createElement('div');

balloon.className = 'balloon';

balloon.style.backgroundColor = `linear-gradient(#e6e6fa, ${colorsMath.floor(Math.random() \* colors.length)})`;

balloon.style.left = Math.random() * (window.innerWidth - 160) + 'px'; /* 调整left值以避免超出屏幕 */

balloon.style.top = Math.random() * (window.innerHeight - 160) + 'px';

document.body.appendChild(balloon);

balloon.addEventListener('click', () => {

balloon.remove();

score++;

scoreElement.textContent = score;

if (score > 15) {

alert('恭喜你!你赢了!');

location.reload(); // 重新加载页面

}

});

}

window.onload = function() {

setInterval(createBalloon, 1000);

createBalloon();

};

</script>

</body>

</html>

相关推荐
2601_963771379 小时前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
蓝银草同学9 小时前
Stream 实战:博客列表排序、过滤与分页(AI 辅助学习 Java 8)
java·前端·后端
2601_9571909010 小时前
飞行影院安装施工指南:场地、动感系统与影片内容配套
大数据·前端·人工智能
爱折腾的小黑牛10 小时前
简记往来批量录入功能的实现:从文本到结构化数据
前端·算法
sunfdf10 小时前
Next.js 新手从零部署到首跑实战指南
开发语言·javascript·ecmascript
YHHLAI10 小时前
Agent 智能体开发实战 · 第六课:MCP 协议 —— 让 Agent 跨进程调用工具
前端·人工智能
SmartBoyW10 小时前
前端死磕:一文彻底搞懂 JS 事件循环 (Event Loop) 与宏微任务
前端·javascript
爱勇宝10 小时前
3位工程师靠“删AI代码”创业,一周收费1万美元:以后最贵的能力,可能不是写代码
前端·后端·架构
Curvatureflight10 小时前
客户端日志上报怎么设计?让线上问题不再只靠用户截图
前端·系统架构