自制HTML游戏网页 制作网页小游戏
gaoyangw 2024-11-13 10:36 31 浏览 0 评论
界面展示
介绍
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>
相关推荐
- 打工人必备!赶紧收藏!DeepSeek的3个SEO隐藏技巧
-
引言:AI如何破解内容创作的“死亡循环”?你是否曾为每天写不完的选题、抓不住的热点、优化不了的排名而焦虑?当AI工具遇上SEO策略,这场“人机协作”的革命正在重塑内容生态。正如埃隆·马斯克所言:“AI...
- 如何提升网站权重(提高网站权重方法)
-
提升网站权重是优化网站在搜索引擎中排名的重要手段,以下是一些关键方法:优质内容:发布原创、有价值的内容是提升权重的核心。确保内容结构清晰,使用合适的关键词,同时避免过度优化。用户体验:优化网站加载速度...
- 小红书运营如何进行内容更新?有哪些频率建议?
-
在小红书上进行内容更新是一项需要策略和规划的工作。随着平台的不断发展,用户的需求和偏好也在不断变化,因此,及时更新内容显得尤为重要。接下来,将从几个方面介绍如何进行小红书内容更新,以及相关的频率建议。...
- 网页ui设计两大关键:响应式和可访问性的秘籍全揭秘
-
在快速发展的互联网时代,网页UI设计已成为连接用户与信息的桥梁。优秀的UI设计不仅能够吸引用户的注意力,还能提升用户体验,促进信息的有效传递。而在这其中,响应式设计和可访问性无疑是两大核心要素,它们共...
- 网站维护攻略:零宕机×极速体验×安全壁垒,让您的业务永远在线
-
网站维护是确保网站稳定运行、持续优化的重要过程,涉及技术管理、内容更新及安全防护等多个方面。作为网站管理员或IT团队的一员,了解和执行网站维护工作对于保持网站的高效运行和用户满意度至关重要。以下是网站...
- Vue应用性能优化实战:8 个提升页面加载速度的关键策略
-
一、构建优化与代码精简1.1代码分割与异步加载...
- 华小锦建站:做好这四点,搭建实用美观企业官网
-
在互联网时代,企业官网已成为推广产品与服务的核心渠道。随着互联网技术的飞速发展,众多企业深刻认识到网络推广的重要性。企业应立足自身,充分利用互联网平台,塑造更具吸引力的网上形象。通过精心搭建网站,宣传...
- 服务器对网站性能的优化(网站服务器速度对seo的影响)
-
在数字时代,网站已成为企业与客户互动的主要窗口。网站的加载速度、稳定性和用户体验直接影响到企业的品牌形象和业务成果。尽管网站优化涉及内容、设计和前端代码等多个方面,但服务器的性能同样扮演着至关重要的角...
- 优化网页性能的时候,需要考虑什么因素呢
-
在优化网页性能时,需要考虑以下关键因素:一、前端性能优化减少资源加载时间压缩图片和多媒体文件:通过压缩图片、视频和音频文件,减小文件大小,从而加快加载速度。选择合适的图片格式(如JPEG、PNG、We...
- 如何对网站进行优化以提高加载速度
-
对网站进行优化以提高加载速度,让.com、.top域名告诉您可以从以下几个方面着手:首先,压缩网站文件是关键。利用压缩算法,如Gzip,来减小CSS、JavaScript等文件的大小,从而缩短用户访问...
- QNAP 威联通 NAS 迅雷+百度云脱机远程下载解决方案
-
QNAP威联通NAS迅雷+百度云脱机远程下载解决方案一、前言家里一直想添置一台NAS,自己之前也折腾过黑群晖,PogoPlug,最终还是选择的QNAP(威联通)的产品,主要用途就是数据的分享和脱...
- 73颗磁力珠被5岁男孩吞下……消化道穿孔只能手术取出
-
“屡禁不止的磁力珠,要创年度磁力珠消化道穿孔之最吗?”连夜做完手术后,浙大儿院普外科章立峰副主任医师忍不住和同事感慨道。11月1日晚,章立峰和同事从一个5岁小男孩的小肠里取出73颗磁力珠。这是他们手术...
- 好用的磁力在线播放下载软件,云盘.吊打迅雷
-
pikpak,目前磁力在线播放下载都吊打某雷的软件。无视某雷屏蔽,解析播放速度也比某雷快。使用很方便。下载链接:https://toapp.mypikpak.com/activity/invited?...
- 6个让你10T硬盘立马爆掉的资源网站,再也不需要去百度上找资源了
-
你还在为找不到资源而烦恼吗?自己在网上总是找不到想要的资源,看这个电脑里面空空荡荡的10T硬盘,真的印证了一句话:"英雄无用武之地"!如果你也是在网上找不到满意的资源,那么不用担心啦!这里小编为大家整...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- 网站建设 (107)
- 网站开发 (47)
- 网络推广哪个平台好 (47)
- 百度收录 (50)
- 网页设计 (44)
- 搜索引擎排名优化 (49)
- 关键词优化工具 (51)
- 外贸网站建设 (56)
- seo整站优化吧 (50)
- 广州seo (47)
- 苏州网站建设 (59)
- 百度搜索推广 (61)
- 关键词优化公司 (51)
- 网页制作 (47)
- 广州网站建设 (48)
- 电商网站建设 (49)
- 百度站长平台 (48)
- 网站收录查询 (46)
- 网站模板 (51)
- 厦门网站建设 (52)
- 百度快照推广 (51)
- 免费网页在线客服系统 (53)
- 雷神代刷网站推广 (53)
- 网站设计模板 (45)
- 一键优化 (47)