自制HTML游戏网页
myzbx 2025-01-02 17:52 23 浏览
界面展示
介绍
HTML(超文本标记语言,HyperText Markup Language)是一种用于创建和构建网页的标准标记语言。它允许将文本、图片、视频、链接等元素组织成网页,以在浏览器中显示。HTML使用一系列成对出现的标签来定义元素,这些标签可以嵌套在一起,从而构建出一个完整的页面结构。
以下是一个简单的HTML示例:
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的简单网页</title>
</head>
<body>
<h1>欢迎来到我的网站</h1>
<p>这是一个简单的段落。</p>
<img src="my-image.jpg" alt="描述图片内容的文本">
<a href="***">点击这里访问示例网站</a>
</body>
</html>
```
在这个示例中,我们使用了以下几个HTML标签:
1. `<!DOCTYPE html>`:声明文档类型为HTML5。
2. `<html>`:根元素,包含整个HTML页面的内容。
3. `<head>`:包含页面的元数据,如字符编码、视口设置和标题等。
4. `<meta charset="UTF-8">`:声明文档使用UTF-8字符编码。
5. `<meta name="viewport" content="width=device-width, initial-scale=1.0">`:设置页面视口,使页面在不同设备上响应式显示。
6. `<title>`:定义网页标题,显示在浏览器的标签页上。
7. `<body>`:包含页面的主体内容,如文本、图片和链接等。
8. `<h1>`:一级标题。
9. `<p>`:段落。
10. `<img>`:图片。
11. `<a>`:超链接。
这只是HTML的基本概念,HTML还具有更多的标签和属性,用于创建更复杂的页面布局和交互效果。随着HTML5的推出,HTML还支持了一些新的功能,如视频、音频、画布(Canvas)和地理定位(Geolocation)等。
下面是我自制的HTML游戏网页。大家可以把它吃掉复制到HTML在线工具里。
一个赞拿走[看]
正文
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>纸牌记忆游戏</title>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
- <style>
- html {
- box-sizing: border-box;
- }
- *,
- *::before,
- *::after {
- box-sizing: inherit;
- }
- html,
- body {
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- font-weight:bolder;
- }
- body {
- background: #ffffff;
- font-size: 16px;
- }
- .container {
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- }
- h1 {
- font-family: 'Gloria Hallelujah', cursive;
- }
- /*纸牌的样式*/
- .deck {
- width: 85%;
- background: #716F71;
- padding: 1rem;
- border-radius: 4px;
- box-shadow: 8px 9px 26px 0 rgba(46, 61, 73, 0.5);
- display: flex;
- flex-wrap: wrap;
- justify-content: space-around;
- align-items: center;
- margin: 0 0 3em;
- }
- .deck .card {
- height: 3.7rem;
- width: 3.7rem;
- margin: 0.2rem 0.2rem;
- background: #141214;;
- font-size: 0;
- color: #ffffff;
- border-radius: 5px;
- cursor: pointer;
- display: flex;
- justify-content: center;
- align-items: center;
- box-shadow: 5px 2px 20px 0 rgba(46, 61, 73, 0.5);
- }
- .deck .card.open {
- transform: rotateY(0);
- background: #02b3e4;
- cursor: default;
- animation-name: flipInY;
- -webkit-backface-visibility: visible;
- backface-visibility: visible;
- animation-duration: .75s;
- }
- .deck .card.show {
- font-size: 33px;
- }
- .deck .card.match {
- cursor: default;
- background: #E5F720;
- font-size: 33px;
- animation-name: rubberBand;
- -webkit-backface-visibility: visible;
- backface-visibility: visible;
- animation-duration: .75s;
- }
- .deck .card.unmatched {
- animation-name: pulse;
- -webkit-backface-visibility: visible;
- backface-visibility: visible;
- animation-duration: .75s;
- background: #e2043b;
- }
- .deck .card.disabled {
- pointer-events: none;
- opacity: 0.9;
- }
- /*分数面板的样式*/
- .score-panel {
- text-align: left;
- margin-bottom: 10px;
- }
- .score-panel .stars {
- margin: 0;
- padding: 0;
- display: inline-block;
- margin: 0 5px 0 0;
- }
- .score-panel .stars li {
- list-style: none;
- display: inline-block;
- }
- .score-panel .restart {
- float: right;
- cursor: pointer;
- }
- .fa-star {
- color: #FFD700;
- }
- .timer {
- display: inline-block;
- margin: 0 1rem;
- }
- /*祝贺面板的样式*/
- .overlay {
- position: fixed;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- background: rgba(0, 0, 0, 0.7);
- transition: opacity 500ms;
- visibility: hidden;
- opacity: 0;
- }
- .overlay:target {
- visibility: visible;
- opacity: 1;
- }
- .popup {
- margin: 70px auto;
- padding: 20px;
- background: #ffffff;
- border-radius: 5px;
- width: 85%;
- position: relative;
- transition: all 5s ease-in-out;
- }
- .popup h2 {
- margin-top: 0;
- color: #333;
- font-family: Tahoma, Arial, sans-serif;
- }
- .popup .close {
- position: absolute;
- top: 20px;
- right: 30px;
- transition: all 200ms;
- font-size: 30px;
- font-weight: bold;
- text-decoration: none;
- color: #333;
- }
- .popup .close:hover {
- color: #E5F720;
- }
- .popup .content-1,
- .content-2 {
- max-height: 30%;
- overflow: auto;
- text-align: center;
- }
- .show {
- visibility: visible;
- opacity: 100;
- }
- #starRating li {
- display: inline-block;
- }
- #play-again {
- background-color: #141214;
- padding: 0.7rem 1rem;
- font-size: 1.1rem;
- display: block;
- margin: 0 auto;
- width: 50%;
- font-family: 'Gloria Hallelujah', cursive;
- color: #ffffff;
- border-radius: 5px;
- }
- /* 卡片打开时的动画 */
- @keyframes flipInY {
- from {
- transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
- animation-timing-function: ease-in;
- opacity: 0;
- }
- 40% {
- transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
- animation-timing-function: ease-in;
- }
- 60% {
- transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
- opacity: 1;
- }
- 80% {
- transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
- }
- to {
- transform: perspective(400px);
- }
- }
- /* 卡片匹配时的动画 */
- @keyframes rubberBand {
- from {
- transform: scale3d(1, 1, 1);
- }
- 30% {
- transform: scale3d(1.25, 0.75, 1);
- }
- 40% {
- transform: scale3d(0.75, 1.25, 1);
- }
- 50% {
- transform: scale3d(1.15, 0.85, 1);
- }
- 65% {
- transform: scale3d(.95, 1.05, 1);
- }
- 75% {
- transform: scale3d(1.05, .95, 1);
- }
- to {
- transform: scale3d(1, 1, 1);
- }
- }
- /* 卡片不匹配时的动画 */
- @keyframes pulse {
- from {
- transform: scale3d(1, 1, 1);
- }
- 50% {
- transform: scale3d(1.2, 1.2, 1.2);
- }
- to {
- transform: scale3d(1, 1, 1);
- }
- }
- /******媒体查询*****/
- /* 适用于 320px 以下的样式*/
- @media (max-width: 320px) {
- .deck {
- width: 85%;
- }
- .deck .card {
- height: 4.7rem;
- width: 4.7rem;
- }
- }
- /* 适用于 768px 以上的样式*/
- @media (min-width: 768px) {
- .container {
- font-size: 22px;
- }
- .deck {
- width: 660px;
- height: 680px;
- }
- .deck .card {
- height: 125px;
- width: 125px;
- }
- .popup {
- width: 60%;
- }
- }
- .page-footer {
- position: fixed;
- right: 0;
- bottom: 20px;
- display: flex;
- align-items: center;
- padding: 5px;
- color: black;
- background: rgba(255, 255, 255, 0.65);
- }
- .page-footer a {
- display: flex;
- margin-left: 4px;
- }
- .touxiang{
- width:24px;
- height:24px;
- }
- </style>
- <!-- 导入bootstrap以及字体图标等样式 -->
- <link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
- </head>
- <body>
- <div class="container">
- <header>
- <h1>纸牌记忆游戏</h1>
- <!-- 署名 -->
- <p align="center">DOLEFULNESS自制</p>
- </header>
- <section class="score-panel">
- <ul class="stars">
- <li><i class="fa fa-star"></i></li>
- <li><i class="fa fa-star"></i></li>
- <li><i class="fa fa-star"></i></li>
- </ul>
- <span class="moves">0</span>
- <div class="timer"></div>
- <div class="restart" onclick="startGame()">
- <i class="fa fa-repeat"></i>
- </div>
- </section>
- <ul class="deck" id="card-deck">
- <li class="card" type="diamond"><i class="fa fa-diamond"></i></li>
- <li class="card" type="plane"><i class="fa fa-paper-plane-o"></i></li>
- <li class="card match" type="anchor"><i class="fa fa-anchor"></i> </li>
- <li class="card" type="bolt" ><i class="fa fa-bolt"></i></li>
- <li class="card" type="cube"><i class="fa fa-cube"></i></li>
- <li class="card match" type="anchor"><i class="fa fa-anchor"></i></li>
- <li class="card" type="leaf"><i class="fa fa-leaf"></i></li>
- <li class="card" type="bicycle"><i class="fa fa-bicycle"></i></li>
- <li class="card" type="diamond"><i class="fa fa-diamond"></i></li>
- <li class="card" type="bomb"><i class="fa fa-bomb"></i></li>
- <li class="card" type="leaf"><i class="fa fa-leaf"></i></li>
- <li class="card" type="bomb"><i class="fa fa-bomb"></i></li>
- <li class="card open show" type="bolt"><i class="fa fa-bolt"></i></li>
- <li class="card" type="bicycle"><i class="fa fa-bicycle"></i></li>
- <li class="card" type="plane"><i class="fa fa-paper-plane-o"></i></li>
- <li class="card" type="cube"><i class="fa fa-cube"></i></li>
- </ul>
- <div id="popup1" class="overlay">
- <div class="popup">
- <h2>恭喜 </h2>
- <a class="close" href="#">×</a>
- <div class="content-1">
- 恭喜你获得了胜利
- </div>
- <div class="content-2">
- <p>你在<span id="totalTime"> </span>内 </p>
- <p>移动了<span id="finalMove"> </span> 次 </p>
- <p>星级: <span id="starRating"></span></p>
- </div>
- <button id="play-again"onclick="playAgain()">
- 再玩一次 </a>
- </button>
- </div>
- </div>
- </div>
- <script>
- // 卡片数组包含所有卡片
- let card = document.getElementsByClassName("card");
- let cards = [...card];
- // 游戏中所有卡片
- const deck = document.getElementById("card-deck");
- // 声明 moves 变量
- let moves = 0;
- let counter = document.querySelector(".moves");
- // 声明星形图标的变量
- const stars = document.querySelectorAll(".fa-star");
- // 声明 matchedCard 的变量
- let matchedCard = document.getElementsByClassName("match");
- // 星级列表
- let starsList = document.querySelectorAll(".stars li");
- // 模板中的关闭图标
- let closeicon = document.querySelector(".close");
- // 声明 modal
- let modal = document.getElementById("popup1")
- // 打开卡片的数组
- var openedCards = [];
- // 洗牌功能
- function shuffle(array) {
- var currentIndex = array.length, temporaryValue, randomIndex;
- while (currentIndex !== 0) {
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex -= 1;
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- };
- // 页面刷新/加载时洗牌
- document.body.onload = startGame();
- // 开始新游戏的功能
- function startGame(){
- // 清空 openCards 数组
- openedCards = [];
- // 洗牌
- cards = shuffle(cards);
- // 从每张卡片中删除所有现有的类
- for (var i = 0; i < cards.length; i++){
- deck.innerHTML = "";
- [].forEach.call(cards, function(item) {
- deck.appendChild(item);
- });
- cards[i].classList.remove("show", "open", "match", "disabled");
- }
- // 重置 moves
- moves = 0;
- counter.innerHTML = moves;
- // 重置 rating
- for (var i= 0; i < stars.length; i++){
- stars[i].style.color = "#FFD700";
- stars[i].style.visibility = "visible";
- }
- // 重置 timer
- second = 0;
- minute = 0;
- hour = 0;
- var timer = document.querySelector(".timer");
- timer.innerHTML = "0 分 0 秒";
- clearInterval(interval);
- }
- // 显示卡片的功能
- var displayCard = function (){
- this.classList.toggle("open");
- this.classList.toggle("show");
- this.classList.toggle("disabled");
- };
- // 将打开的卡片添加到 OpenedCards 列表并检查卡片是否匹配
- function cardOpen() {
- openedCards.push(this);
- var len = openedCards.length;
- if(len === 2){
- moveCounter();
- if(openedCards[0].type === openedCards[1].type){
- matched();
- } else {
- unmatched();
- }
- }
- };
- // 当卡片匹配时的功能
- function matched(){
- openedCards[0].classList.add("match", "disabled");
- openedCards[1].classList.add("match", "disabled");
- openedCards[0].classList.remove("show", "open", "no-event");
- openedCards[1].classList.remove("show", "open", "no-event");
- openedCards = [];
- }
- // 当卡片不匹配时的功能
- function unmatched(){
- openedCards[0].classList.add("unmatched");
- openedCards[1].classList.add("unmatched");
- disable();
- setTimeout(function(){
- openedCards[0].classList.remove("show", "open", "no-event","unmatched");
- openedCards[1].classList.remove("show", "open", "no-event","unmatched");
- enable();
- openedCards = [];
- },1100);
- }
- // 暂时禁用卡片的功能
- function disable(){
- Array.prototype.filter.call(cards, function(card){
- card.classList.add('disabled');
- });
- }
- // 启用卡片并禁用匹配的卡片的功能
- function enable(){
- Array.prototype.filter.call(cards, function(card){
- card.classList.remove('disabled');
- for(var i = 0; i < matchedCard.length; i++){
- matchedCard[i].classList.add("disabled");
- }
- });
- }
- // 计算玩家的动作的功能
- function moveCounter(){
- moves++;
- counter.innerHTML = moves;
- // 第一次点击时启动计时器
- if(moves == 1){
- second = 0;
- minute = 0;
- hour = 0;
- startTimer();
- }
- // 根据移动次数设置星级
- if (moves > 8 && moves < 12){
- for( i= 0; i < 3; i++){
- if(i > 1){
- stars[i].style.visibility = "collapse";
- }
- }
- }
- else if (moves > 13){
- for( i= 0; i < 3; i++){
- if(i > 0){
- stars[i].style.visibility = "collapse";
- }
- }
- }
- }
- // 显示游戏的时间
- var second = 0, minute = 0; hour = 0;
- var timer = document.querySelector(".timer");
- var interval;
- function startTimer(){
- interval = setInterval(function(){
- timer.innerHTML = minute+" 分"+second+" 秒";
- second++;
- if(second == 60){
- minute++;
- second=0;
- }
- if(minute == 60){
- hour++;
- minute = 0;
- }
- },1000);
- }
- // 所有卡片匹配匹配时展示恭喜界面,显示移动次数时间和等级
- function congratulations(){
- if (matchedCard.length == 16){
- clearInterval(interval);
- finalTime = timer.innerHTML;
- // 显示祝贺模板
- modal.classList.add("show");
- // 声明星级变量
- var starRating = document.querySelector(".stars").innerHTML;
- // 显示移动、评级、时间
- document.getElementById("finalMove").innerHTML = moves;
- document.getElementById("starRating").innerHTML = starRating;
- document.getElementById("totalTime").innerHTML = finalTime;
- //模板上的关闭图标
- closeModal();
- };
- }
- // 界面上的关闭图标
- function closeModal(){
- closeicon.addEventListener("click", function(e){
- modal.classList.remove("show");
- startGame();
- });
- }
- // 再次游戏功能
- function playAgain(){
- modal.classList.remove("show");
- startGame();
- }
- // 循环以将事件侦听器添加到每张卡片
- for (var i = 0; i < cards.length; i++){
- card = cards[i];
- card.addEventListener("click", displayCard);
- card.addEventListener("click", cardOpen);
- card.addEventListener("click",congratulations);
- };
- </script>
- <script src="https://sygjx.com/js/script.js"></script>
- </body>
- </html>
- 上一篇:H5特点及新增特性
- 下一篇:前端开发新手入门:Web开发工具有哪些?
相关推荐
- 网易《逆水寒》手游【逆水侠棋】首次正式更新,近 50 项调整优化
-
IT之家7月23日消息,网易《逆水寒》手游于6月27日迎来二周年资料片,推出了特色自走棋玩法【逆水侠棋】。游戏官方今日宣布,【逆水侠棋】玩法上线以来已经进行了4000多万场的对局,...
- 消息称英特尔Arrow Lake-S Refresh处理器下半年发布,升级NPU
-
IT之家7月7日消息,韩媒ZDNETKorea当地时间4日报道称,英特尔酷睿Ultra200S"ArrowLake-S"处理器的Refresh刷新版本将...
- 用户中心——比如:腾讯的QQ账号可以登录到很多应用当中 02
-
用户中心——比如:腾讯的QQ账号可以登录到很多应用当中02@[toc]前端登录注册blankTarget表示是一个用户点击时跳转时,是打开一个新的页面还是,在本地页面覆盖。constants公共...
- 英特尔发布6862图形驱动,相比Q1版本性能最高提升37%
-
IT之家7月11日消息,英特尔公司于7月8日,面向锐炫(Arc)B、A系列显卡、集成Arc核显的酷睿Ultra系列处理器,发布了32.0.101.6862(Q2.25)图...
- Cryin:BLG打不过AL,与T1无缘了!JDG首发xiaoxu,WBG世界赛有望
-
【关注残影游戏,看LOL最新资讯,来看下这一期的撸圈日报吧!】TOP1Cryin:BLG打不过AL,与T1无缘了!在MSI的比赛中,AL与BLG双双输给了LCK,只不过AL终究是和GEN打满了五局,但...
- 安装SOLIDWORKS出现错误:“已安装较新版本”如何解决?
-
-SOLIDWORKS常见问题及技巧分享52-PART1:客户问题客户使用了SOLIDWORKS2024SP5版本作业,由于公司接到一个订单要求使用SOLIDWORKS2018...
- 《托尼·霍克职业滑板3+4》Xbox平台版本现已开启预载
-
《托尼·霍克职业滑板3+4》现已在Xbox平台开启预载,玩家可提前为7月11日的正式发售做准备。此外,官方还公布了XboxSeriesX|S版本的一些新细节。在《托尼·霍克职业滑板1+2》发售近...
- SRAM套件会让整车更轻吗?车手战车:罗格利奇的S-Works Tarmac SL8
-
普里莫茨·罗格利奇(PrimozRoglic)以红牛-博拉-汉斯格雅车队主将的身份开启了2025年环法之旅。随着高山赛段的争夺,环法进入白热化阶段,罗格利奇的总成绩也在不断上升中。弗洛里...
- MST 全新一代 RMX 4 S PRO 正式登场
-
MST(MaxSpeedTechnology,得隆科技)正式宣布,下一代RMX漂移底盘即将登场,命名为RMX4。全新RMX4延续当前主流的后驱(RWD)漂移布局,在经典架构的基础上大...
- S960Q钢板综合解析S960Q钢板化学成分
-
S960Q钢板综合解析(欧标EN10025-6)一、化学成分S960Q采用低碳+微合金化设计,化学成分严格控制杂质元素,核心配比如下:元素含量范围关键作用碳(C)≤0.20%保障焊接性及韧性锰...
- 英伟达优化DLSS 4:Transformer模型显存占用减少20%
-
IT之家6月29日消息,除了推出DLSS4正式版,英伟达还在其最新的DLSSSDK版本中对显存(VRAM)使用进行了优化。VideoCardz发现,DLSS310.3.0将...
- 消息称三星工艺高通SM8850s“套片报价更低,可能明年才会上”
-
IT之家7月2日消息,消息源@数码闲聊站今日表示,其最近又“摸到”了采用三星晶圆代工SF2工艺、代号为SM8850s的高通SM8850旗舰移动芯片变体。这位博主表示:“听说(...
- 防止开源供应链“下毒”,谷歌推出OSS Rebuild项目
-
IT之家7月22日消息,为提升开源项目的安全性,谷歌今日推出了OSSRebuild,开发者可利用该工具通过重现构建过程来验证开源软件包的完整性,从而避免开源供应链“下毒”情况。谷歌介绍称,...
- 向经典致敬!2025本田GB350/S披上70年代蓝白新色登场
-
Honda发表了新复古车款GB350及其衍生版本GB350S的2025年款。这是自2023年以来,时隔两年的改款,除了变更了头尾灯及仪表的规格外,还首次采用了双色调配色。车辆规格与配备方面则没有变更。...
- 铠侠推出目前最大容量固态硬盘:企业级LC9新增245.76TB版本
-
IT之家7月22日消息,铠侠日本当地时间今日宣布为主打大容量存储的LC9系列企业级固态硬盘新增245.76TB版本。这一新型号在成为目前最大容量SSD的同时也是首款来到256TB...
- 一周热门
- 最近发表
-
- 网易《逆水寒》手游【逆水侠棋】首次正式更新,近 50 项调整优化
- 消息称英特尔Arrow Lake-S Refresh处理器下半年发布,升级NPU
- 用户中心——比如:腾讯的QQ账号可以登录到很多应用当中 02
- 英特尔发布6862图形驱动,相比Q1版本性能最高提升37%
- Cryin:BLG打不过AL,与T1无缘了!JDG首发xiaoxu,WBG世界赛有望
- 安装SOLIDWORKS出现错误:“已安装较新版本”如何解决?
- 《托尼·霍克职业滑板3+4》Xbox平台版本现已开启预载
- SRAM套件会让整车更轻吗?车手战车:罗格利奇的S-Works Tarmac SL8
- MST 全新一代 RMX 4 S PRO 正式登场
- S960Q钢板综合解析S960Q钢板化学成分
- 标签列表
-
- HTML 简介 (30)
- HTML 响应式设计 (31)
- HTML URL 编码 (32)
- HTML Web 服务器 (31)
- HTML 表单属性 (32)
- HTML 音频 (31)
- HTML5 支持 (33)
- HTML API (36)
- HTML 总结 (32)
- HTML 全局属性 (32)
- HTML 事件 (31)
- HTML 画布 (32)
- HTTP 方法 (30)
- 键盘快捷键 (30)
- CSS 语法 (35)
- CSS 轮廓宽度 (31)
- CSS 谷歌字体 (33)
- CSS 链接 (31)
- CSS 定位 (31)
- CSS 图片库 (32)
- CSS 图像精灵 (31)
- SVG 文本 (32)
- 时钟启动 (33)
- HTML 游戏 (34)
- JS Loop For (32)