百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

自制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在线工具里。

一个赞拿走[看]




正文

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>纸牌记忆游戏</title>
  6. <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">

  7. <style>
  8. html {
  9. box-sizing: border-box;
  10. }

  11. *,
  12. *::before,
  13. *::after {
  14. box-sizing: inherit;
  15. }

  16. html,
  17. body {
  18. width: 100%;
  19. height: 100%;
  20. margin: 0;
  21. padding: 0;
  22. font-weight:bolder;
  23. }

  24. body {
  25. background: #ffffff;
  26. font-size: 16px;
  27. }

  28. .container {
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. flex-direction: column;
  33. }

  34. h1 {
  35. font-family: 'Gloria Hallelujah', cursive;
  36. }

  37. /*纸牌的样式*/
  38. .deck {
  39. width: 85%;
  40. background: #716F71;
  41. padding: 1rem;
  42. border-radius: 4px;
  43. box-shadow: 8px 9px 26px 0 rgba(46, 61, 73, 0.5);
  44. display: flex;
  45. flex-wrap: wrap;
  46. justify-content: space-around;
  47. align-items: center;
  48. margin: 0 0 3em;
  49. }

  50. .deck .card {
  51. height: 3.7rem;
  52. width: 3.7rem;
  53. margin: 0.2rem 0.2rem;
  54. background: #141214;;
  55. font-size: 0;
  56. color: #ffffff;
  57. border-radius: 5px;
  58. cursor: pointer;
  59. display: flex;
  60. justify-content: center;
  61. align-items: center;
  62. box-shadow: 5px 2px 20px 0 rgba(46, 61, 73, 0.5);
  63. }

  64. .deck .card.open {
  65. transform: rotateY(0);
  66. background: #02b3e4;
  67. cursor: default;
  68. animation-name: flipInY;
  69. -webkit-backface-visibility: visible;
  70. backface-visibility: visible;
  71. animation-duration: .75s;
  72. }

  73. .deck .card.show {
  74. font-size: 33px;
  75. }

  76. .deck .card.match {
  77. cursor: default;
  78. background: #E5F720;
  79. font-size: 33px;
  80. animation-name: rubberBand;
  81. -webkit-backface-visibility: visible;
  82. backface-visibility: visible;
  83. animation-duration: .75s;
  84. }

  85. .deck .card.unmatched {
  86. animation-name: pulse;
  87. -webkit-backface-visibility: visible;
  88. backface-visibility: visible;
  89. animation-duration: .75s;
  90. background: #e2043b;
  91. }

  92. .deck .card.disabled {
  93. pointer-events: none;
  94. opacity: 0.9;
  95. }

  96. /*分数面板的样式*/
  97. .score-panel {
  98. text-align: left;
  99. margin-bottom: 10px;
  100. }

  101. .score-panel .stars {
  102. margin: 0;
  103. padding: 0;
  104. display: inline-block;
  105. margin: 0 5px 0 0;
  106. }

  107. .score-panel .stars li {
  108. list-style: none;
  109. display: inline-block;
  110. }

  111. .score-panel .restart {
  112. float: right;
  113. cursor: pointer;
  114. }

  115. .fa-star {
  116. color: #FFD700;
  117. }

  118. .timer {
  119. display: inline-block;
  120. margin: 0 1rem;

  121. }

  122. /*祝贺面板的样式*/
  123. .overlay {
  124. position: fixed;
  125. top: 0;
  126. bottom: 0;
  127. left: 0;
  128. right: 0;
  129. background: rgba(0, 0, 0, 0.7);
  130. transition: opacity 500ms;
  131. visibility: hidden;
  132. opacity: 0;
  133. }

  134. .overlay:target {
  135. visibility: visible;
  136. opacity: 1;
  137. }

  138. .popup {
  139. margin: 70px auto;
  140. padding: 20px;
  141. background: #ffffff;
  142. border-radius: 5px;
  143. width: 85%;
  144. position: relative;
  145. transition: all 5s ease-in-out;
  146. }

  147. .popup h2 {
  148. margin-top: 0;
  149. color: #333;
  150. font-family: Tahoma, Arial, sans-serif;
  151. }

  152. .popup .close {
  153. position: absolute;
  154. top: 20px;
  155. right: 30px;
  156. transition: all 200ms;
  157. font-size: 30px;
  158. font-weight: bold;
  159. text-decoration: none;
  160. color: #333;
  161. }

  162. .popup .close:hover {
  163. color: #E5F720;
  164. }

  165. .popup .content-1,
  166. .content-2 {
  167. max-height: 30%;
  168. overflow: auto;
  169. text-align: center;
  170. }

  171. .show {
  172. visibility: visible;
  173. opacity: 100;
  174. }

  175. #starRating li {
  176. display: inline-block;
  177. }

  178. #play-again {
  179. background-color: #141214;
  180. padding: 0.7rem 1rem;
  181. font-size: 1.1rem;
  182. display: block;
  183. margin: 0 auto;
  184. width: 50%;
  185. font-family: 'Gloria Hallelujah', cursive;
  186. color: #ffffff;
  187. border-radius: 5px;
  188. }

  189. /* 卡片打开时的动画 */

  190. @keyframes flipInY {
  191. from {
  192. transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
  193. animation-timing-function: ease-in;
  194. opacity: 0;
  195. }

  196. 40% {
  197. transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
  198. animation-timing-function: ease-in;
  199. }

  200. 60% {
  201. transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
  202. opacity: 1;
  203. }

  204. 80% {
  205. transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
  206. }

  207. to {
  208. transform: perspective(400px);
  209. }
  210. }

  211. /* 卡片匹配时的动画 */
  212. @keyframes rubberBand {
  213. from {
  214. transform: scale3d(1, 1, 1);
  215. }

  216. 30% {
  217. transform: scale3d(1.25, 0.75, 1);
  218. }

  219. 40% {
  220. transform: scale3d(0.75, 1.25, 1);
  221. }

  222. 50% {
  223. transform: scale3d(1.15, 0.85, 1);
  224. }

  225. 65% {
  226. transform: scale3d(.95, 1.05, 1);
  227. }

  228. 75% {
  229. transform: scale3d(1.05, .95, 1);
  230. }

  231. to {
  232. transform: scale3d(1, 1, 1);
  233. }
  234. }

  235. /* 卡片不匹配时的动画 */
  236. @keyframes pulse {
  237. from {
  238. transform: scale3d(1, 1, 1);
  239. }

  240. 50% {
  241. transform: scale3d(1.2, 1.2, 1.2);
  242. }

  243. to {
  244. transform: scale3d(1, 1, 1);
  245. }
  246. }

  247. /******媒体查询*****/
  248. /* 适用于 320px 以下的样式*/
  249. @media (max-width: 320px) {
  250. .deck {
  251. width: 85%;
  252. }

  253. .deck .card {
  254. height: 4.7rem;
  255. width: 4.7rem;
  256. }
  257. }

  258. /* 适用于 768px 以上的样式*/
  259. @media (min-width: 768px) {
  260. .container {
  261. font-size: 22px;
  262. }

  263. .deck {
  264. width: 660px;
  265. height: 680px;
  266. }

  267. .deck .card {
  268. height: 125px;
  269. width: 125px;
  270. }

  271. .popup {
  272. width: 60%;
  273. }
  274. }
  275. .page-footer {
  276. position: fixed;
  277. right: 0;
  278. bottom: 20px;
  279. display: flex;
  280. align-items: center;
  281. padding: 5px;
  282. color: black;
  283. background: rgba(255, 255, 255, 0.65);
  284. }

  285. .page-footer a {
  286. display: flex;
  287. margin-left: 4px;
  288. }
  289. .touxiang{
  290. width:24px;
  291. height:24px;
  292. }
  293. </style>
  294. <!-- 导入bootstrap以及字体图标等样式 -->
  295. <link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


  296. </head>
  297. <body>
  298. <div class="container">
  299. <header>
  300. <h1>纸牌记忆游戏</h1>
  301. <!-- 署名 -->
  302. <p align="center">DOLEFULNESS自制</p>
  303. </header>
  304. <section class="score-panel">
  305. <ul class="stars">
  306. <li><i class="fa fa-star"></i></li>
  307. <li><i class="fa fa-star"></i></li>
  308. <li><i class="fa fa-star"></i></li>
  309. </ul>
  310. <span class="moves">0</span>
  311. <div class="timer"></div>
  312. <div class="restart" onclick="startGame()">
  313. <i class="fa fa-repeat"></i>
  314. </div>
  315. </section>
  316. <ul class="deck" id="card-deck">
  317. <li class="card" type="diamond"><i class="fa fa-diamond"></i></li>
  318. <li class="card" type="plane"><i class="fa fa-paper-plane-o"></i></li>
  319. <li class="card match" type="anchor"><i class="fa fa-anchor"></i> </li>
  320. <li class="card" type="bolt" ><i class="fa fa-bolt"></i></li>
  321. <li class="card" type="cube"><i class="fa fa-cube"></i></li>
  322. <li class="card match" type="anchor"><i class="fa fa-anchor"></i></li>
  323. <li class="card" type="leaf"><i class="fa fa-leaf"></i></li>
  324. <li class="card" type="bicycle"><i class="fa fa-bicycle"></i></li>
  325. <li class="card" type="diamond"><i class="fa fa-diamond"></i></li>
  326. <li class="card" type="bomb"><i class="fa fa-bomb"></i></li>
  327. <li class="card" type="leaf"><i class="fa fa-leaf"></i></li>
  328. <li class="card" type="bomb"><i class="fa fa-bomb"></i></li>
  329. <li class="card open show" type="bolt"><i class="fa fa-bolt"></i></li>
  330. <li class="card" type="bicycle"><i class="fa fa-bicycle"></i></li>
  331. <li class="card" type="plane"><i class="fa fa-paper-plane-o"></i></li>
  332. <li class="card" type="cube"><i class="fa fa-cube"></i></li>
  333. </ul>
  334. <div id="popup1" class="overlay">
  335. <div class="popup">
  336. <h2>恭喜 </h2>
  337. <a class="close" href="#">×</a>
  338. <div class="content-1">
  339. 恭喜你获得了胜利
  340. </div>
  341. <div class="content-2">
  342. <p>你在<span id="totalTime"> </span>内 </p>
  343. <p>移动了<span id="finalMove"> </span> 次 </p>
  344. <p>星级: <span id="starRating"></span></p>
  345. </div>
  346. <button id="play-again"onclick="playAgain()">
  347. 再玩一次 </a>
  348. </button>
  349. </div>
  350. </div>

  351. </div>
  352. <script>
  353. // 卡片数组包含所有卡片
  354. let card = document.getElementsByClassName("card");
  355. let cards = [...card];

  356. // 游戏中所有卡片
  357. const deck = document.getElementById("card-deck");

  358. // 声明 moves 变量
  359. let moves = 0;
  360. let counter = document.querySelector(".moves");

  361. // 声明星形图标的变量
  362. const stars = document.querySelectorAll(".fa-star");

  363. // 声明 matchedCard 的变量
  364. let matchedCard = document.getElementsByClassName("match");

  365. // 星级列表
  366. let starsList = document.querySelectorAll(".stars li");

  367. // 模板中的关闭图标
  368. let closeicon = document.querySelector(".close");

  369. // 声明 modal
  370. let modal = document.getElementById("popup1")

  371. // 打开卡片的数组
  372. var openedCards = [];


  373. // 洗牌功能
  374. function shuffle(array) {
  375. var currentIndex = array.length, temporaryValue, randomIndex;

  376. while (currentIndex !== 0) {
  377. randomIndex = Math.floor(Math.random() * currentIndex);
  378. currentIndex -= 1;
  379. temporaryValue = array[currentIndex];
  380. array[currentIndex] = array[randomIndex];
  381. array[randomIndex] = temporaryValue;
  382. }

  383. return array;
  384. };


  385. // 页面刷新/加载时洗牌
  386. document.body.onload = startGame();

  387. // 开始新游戏的功能
  388. function startGame(){

  389. // 清空 openCards 数组
  390. openedCards = [];

  391. // 洗牌
  392. cards = shuffle(cards);
  393. // 从每张卡片中删除所有现有的类
  394. for (var i = 0; i < cards.length; i++){
  395. deck.innerHTML = "";
  396. [].forEach.call(cards, function(item) {
  397. deck.appendChild(item);
  398. });
  399. cards[i].classList.remove("show", "open", "match", "disabled");
  400. }
  401. // 重置 moves
  402. moves = 0;
  403. counter.innerHTML = moves;
  404. // 重置 rating
  405. for (var i= 0; i < stars.length; i++){
  406. stars[i].style.color = "#FFD700";
  407. stars[i].style.visibility = "visible";
  408. }
  409. // 重置 timer
  410. second = 0;
  411. minute = 0;
  412. hour = 0;
  413. var timer = document.querySelector(".timer");
  414. timer.innerHTML = "0 分 0 秒";
  415. clearInterval(interval);
  416. }


  417. // 显示卡片的功能
  418. var displayCard = function (){
  419. this.classList.toggle("open");
  420. this.classList.toggle("show");
  421. this.classList.toggle("disabled");
  422. };


  423. // 将打开的卡片添加到 OpenedCards 列表并检查卡片是否匹配
  424. function cardOpen() {
  425. openedCards.push(this);
  426. var len = openedCards.length;
  427. if(len === 2){
  428. moveCounter();
  429. if(openedCards[0].type === openedCards[1].type){
  430. matched();
  431. } else {
  432. unmatched();
  433. }
  434. }
  435. };


  436. // 当卡片匹配时的功能
  437. function matched(){
  438. openedCards[0].classList.add("match", "disabled");
  439. openedCards[1].classList.add("match", "disabled");
  440. openedCards[0].classList.remove("show", "open", "no-event");
  441. openedCards[1].classList.remove("show", "open", "no-event");
  442. openedCards = [];
  443. }


  444. // 当卡片不匹配时的功能
  445. function unmatched(){
  446. openedCards[0].classList.add("unmatched");
  447. openedCards[1].classList.add("unmatched");
  448. disable();
  449. setTimeout(function(){
  450. openedCards[0].classList.remove("show", "open", "no-event","unmatched");
  451. openedCards[1].classList.remove("show", "open", "no-event","unmatched");
  452. enable();
  453. openedCards = [];
  454. },1100);
  455. }


  456. // 暂时禁用卡片的功能
  457. function disable(){
  458. Array.prototype.filter.call(cards, function(card){
  459. card.classList.add('disabled');
  460. });
  461. }


  462. // 启用卡片并禁用匹配的卡片的功能
  463. function enable(){
  464. Array.prototype.filter.call(cards, function(card){
  465. card.classList.remove('disabled');
  466. for(var i = 0; i < matchedCard.length; i++){
  467. matchedCard[i].classList.add("disabled");
  468. }
  469. });
  470. }


  471. // 计算玩家的动作的功能
  472. function moveCounter(){
  473. moves++;
  474. counter.innerHTML = moves;
  475. // 第一次点击时启动计时器
  476. if(moves == 1){
  477. second = 0;
  478. minute = 0;
  479. hour = 0;
  480. startTimer();
  481. }
  482. // 根据移动次数设置星级
  483. if (moves > 8 && moves < 12){
  484. for( i= 0; i < 3; i++){
  485. if(i > 1){
  486. stars[i].style.visibility = "collapse";
  487. }
  488. }
  489. }
  490. else if (moves > 13){
  491. for( i= 0; i < 3; i++){
  492. if(i > 0){
  493. stars[i].style.visibility = "collapse";
  494. }
  495. }
  496. }
  497. }


  498. // 显示游戏的时间
  499. var second = 0, minute = 0; hour = 0;
  500. var timer = document.querySelector(".timer");
  501. var interval;
  502. function startTimer(){
  503. interval = setInterval(function(){
  504. timer.innerHTML = minute+" 分"+second+" 秒";
  505. second++;
  506. if(second == 60){
  507. minute++;
  508. second=0;
  509. }
  510. if(minute == 60){
  511. hour++;
  512. minute = 0;
  513. }
  514. },1000);
  515. }


  516. // 所有卡片匹配匹配时展示恭喜界面,显示移动次数时间和等级
  517. function congratulations(){
  518. if (matchedCard.length == 16){
  519. clearInterval(interval);
  520. finalTime = timer.innerHTML;

  521. // 显示祝贺模板
  522. modal.classList.add("show");

  523. // 声明星级变量
  524. var starRating = document.querySelector(".stars").innerHTML;

  525. // 显示移动、评级、时间
  526. document.getElementById("finalMove").innerHTML = moves;
  527. document.getElementById("starRating").innerHTML = starRating;
  528. document.getElementById("totalTime").innerHTML = finalTime;

  529. //模板上的关闭图标
  530. closeModal();
  531. };
  532. }


  533. // 界面上的关闭图标
  534. function closeModal(){
  535. closeicon.addEventListener("click", function(e){
  536. modal.classList.remove("show");
  537. startGame();
  538. });
  539. }


  540. // 再次游戏功能
  541. function playAgain(){
  542. modal.classList.remove("show");
  543. startGame();
  544. }


  545. // 循环以将事件侦听器添加到每张卡片
  546. for (var i = 0; i < cards.length; i++){
  547. card = cards[i];
  548. card.addEventListener("click", displayCard);
  549. card.addEventListener("click", cardOpen);
  550. card.addEventListener("click",congratulations);
  551. };

  552. </script>
  553. <script src="https://sygjx.com/js/script.js"></script>
  554. </body>
  555. </html>

相关推荐

网易《逆水寒》手游【逆水侠棋】首次正式更新,近 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...