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>

相关推荐
拖孩15 分钟前
AI 帮我写的小程序「厨菜记」上线满月了,挣了两百块!!!
前端·后端·微信小程序
用户3600555790015 分钟前
Kestrel_VLLM - 13 · 为什么排除 MoE FFN Tiling 与 Tensor Core
前端
Hilaku25 分钟前
AI 流式输出都用 SSE,什么时候必须换 WebSocket?
前端·javascript·程序员
奇牙coding33 分钟前
Codex CLI 升级后多文件编辑静默失效:config.yaml 枚举变更排查与修复指南
java·前端·javascript·ai
小羊没烦恼!40 分钟前
Ajax与JSON的一些总结
android·java·前端·数据库·mysql·算法·okhttp
程序员老赵42 分钟前
Docker 部署 Filestash:轻松搭建浏览器文件管理平台
前端·docker·开源
夏天要喝冰可乐44 分钟前
给 23 万字修仙小说造个阅读站:浏览器内打包 EPUB 分页阅读 + 三主题实战
前端·产品·全栈
茶底世界之下1 小时前
林间步道要不要加暗角?用 Awaking 把强度收在20%
前端·ios·图片资源
执子念的飞鱼1 小时前
纯前端预览 275 种文件格式是怎么做到的
前端·vue.js·react.js
行者全栈架构师1 小时前
【鸿蒙心迹】互动卡片全链路——把核心功能放到桌面(FormKit 实战)(HarmonyOS 7.x)
前端·算法·架构