50 Projects(大抵會不足50個,畢竟目的是瞭解語法構造去製作游戲)

来源:https://www.cnblogs.com/Holdpark/archive/2022/06/16/16381691.html
-Advertisement-
Play Games

50 Projects 01 Expanding Cards(附帶新手菜雞註釋) Live Demo HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compati ...


50 Projects

01 Expanding Cards(附帶新手菜雞註釋)

Live Demo

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Expanding cards</title>
    <link rel="stylesheet" href="/static/css/Expanding-cards.css">
</head>
<body>
    <div class="container">
        <div class="panel active" style="background-image: url('https://images.unsplash.com/photo-1558979158-65a1eaa08691?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Explore World</h3>
        </div>
        <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1572276596237-5db2c3e16c5d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Wild Forest</h3>
          </div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1353&q=80')">
            <h3>Sunny Beach</h3>
          </div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1551009175-8a68da93d5f9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1351&q=80')">
            <h3>City on Winter</h3>
          </div>
          <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
            <h3>Mountains - Clouds</h3>
          </div>
    </div>
    <script type="module" src="/js/Expanding-cards.js"></script>
</body>
</html>

CSS

* {
    box-sizing: border-box;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    margin: 0;
}

.container {
    display: flex;
    width: 90vw;
}

.panel {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 80vh;
    border-radius: 50px;
    color: #fff;
    cursor:  pointer;
    /* 增長繫數,這樣會使圖片有豎條感覺 */
    flex: 0.5;
    margin: 10px;
    position: relative;
    /* 過渡方式,好多動畫用到這個,看來著重要學一下,不過這個all好像去掉不影響大局? */
    transition: all 700ms ease-in;
    /* 時間影響展示時間,感覺調節時間匹配更好 */
}

.panel h3 {
    font-size: 24px;
    position: absolute;
    /* 定義說明文字位置 */
    bottom: 20px;
    left: 20px;
    margin: 0;
    /* 文字透明度 */
    opacity: 0;
}

.active {
    /* 這個MDN上說是增長繫數,就是比值可以這樣說吧,按我來講 */
    flex: 5;
}

.active h3 {
    /* 如果有active屬性,就將說明文字顯現 */
    opacity: 1;
    transition: opacity 0.3s ease-in 0.4s;
}

@media (max-width: 480px) {
    /* 一般而言這種都是電腦展示吧,所以很雞肋?當然依然不可或缺,可以不用,但不能沒有 */
    .container {
        width: 100vh;
    }
}
/* 下麵這個真的不知道為什麼有啊 */
/* .panel:nth-of-type(4),
.panel:nth-of-type(5) {
    display: none;
} */


JS

const panels = document.querySelectorAll('.panel');
// 找到pnael標簽,這應該是列;
// console.log(panels);


// 遍歷所有的元素,查看誰被點擊了,找到之後將其他元素的active全部清除,併為當前屬性添加active
panels.forEach(function(panel) { //遍歷 panels 序列
    panel.addEventListener('click', function(){
        removeActiveClasses(); //移除 active標簽
        panel.classList.add('active');
    });
});

function removeActiveClasses () {
    panels.forEach(function (panel) {
        panel.classList.remove('active');
    })
}

Live Demo

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hidden-search</title>
    <link rel="stylesheet" href="/static/css/hidden-search.css">
    <link rel="stylesheet" href="/third-part/font-awesome-4.7.0/css/font-awesome.min.css">
    
</head>
<body>
    <div class="search">
        <input type="text" class="input" placeholder="Search...">
        <button class="btn">
            <i class="fa fa-search" aria-hidden="true"></i>
        </button>
    </div>
    <script type="module" src="/js/hidden-search.js"></script>
</body>
</html>

CSS

* {
    box-sizing: border-box;
}

 body {
     /* 背景圖片為漸變色 */
    background-image: linear-gradient(90deg,#7d5fff,#7158e2);
    /* flex佈局 */
    display: flex;
    /* 豎直居中 */
    align-items: center;
    /* 水平居中 */
    justify-content: center;
    /* 非常奇怪啊,有100vh可以居中,100%不成 */
    height: 100vh;
    overflow: hidden;
    margin: 0;
}  

.search {
    position: relative;
    height: 50px;
}

.search .input {
    background-color: #fff;
    border: 0;
    font-size: 18px;
    padding: 15px;
    height: 50px;
    width: 50px;
    /* 轉變屬性width */
    transition : width 0.3s ease;

}

.btn {
    background-color: #fff;
    border: 0;
    cursor: pointer;
    font-size: 24px;
    position: absolute;
    top: 0;
    left: 0;
    height: 50px;
    width: 50px;
    /* 平滑移動 */
    transition : transform 0.3s ease;
}
.btn:focus,
.input:focus {
    outline: none
}

.active .input {
    width: 200px;
  }

.active .btn {
    /* 向X軸偏移198px */
    transform: translateX(198px);
  }



JS

let search = document.querySelector('.search');
let btn = document.querySelector('.btn');
let input = document.querySelector('.input');

// 添加監聽函數
btn.addEventListener('click',function(e) {
    // 如果active已經存在,則移除它,否則添加屬性
    search.classList.toggle('active');
    // 效果:<div class="search active"></div>
    console.log(search);
    // input.focus();
});

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • springboot整合ueditor實現圖片上傳和文件上傳功能 寫在前面: 在閱讀本篇之前,請先按照我的這篇隨筆完成對ueditor的前期配置工作: springboot+layui 整合百度富文本編輯器ueditor入門使用教程(踩過的坑)https://www.cnblogs.com/rain ...
  • 這幾天更新有點小慢,逐漸開始回歸狀態了。儘快把這個後臺做完,要開始vue3了 3.添加修改品牌 用到組件 Dialog 對話框,其中visible.sync這個配置是修改他的顯示隱藏的,label-width是這個標題的寬度 然後上傳頭像的按鈕,upload組件,他有自己的一些樣式記得複製在styl ...
  • 個人對瀑布流佈局理解: 每列的寬度相等而高度不等,且第二行的第一個容器需要放在第一行高度最小的容器下麵,依次類推放置。 附上代碼: 代碼僅實現了瀑布流的佈局方式和 resize 監聽,如果大家有需要,可以自己拓展下:實現監聽滾動事件,頁面滾動載入圖片的功能。 代碼中寫了詳細註釋,可以直接使用。 <! ...
  • 前言 Emmet是一款文本編輯器/IDE的插件,用來快速生成複雜的HTML代碼,只要掌握一些常用的語法(類似於CSS選擇器),就可以減少重覆編碼的工作,真的提升開發效率之利器。 所有的操作都是按下tab鍵即可瞬間完成。 一、相關語法 1. 用.來生成類名 div.aaa 按tab後生成如下: <di ...
  • html標簽屬性大全 html標簽屬性大全從網上搜集整理的常用html標簽,供朋友們交流學習html用。 html標簽<marquee> <marquee>...</marquee>普通捲動 <marquee behavior=slide>...</marquee>滑動 <marquee behav ...
  • 以下是小編整理的部分html關鍵字,專門給有需要的朋友進行打字練慣用,通過打字練習的方式,既提高了打字速度,又可以熟悉html關鍵字~~~ www, url, http, W3C, html, htm, head, body, title, br, hr, font, font-style, fon ...
  • 1、瀏覽器列印相對還是比較簡單的,但也導致控制起來就麻煩。對於簡單的列印需求直接用js調用window.print()即可。如果想要更好的控制列印結果,那這個就不能滿足了。 2、市面上有挺多專門做列印功能的商用插件,要不收費,要不免費版閹割有水印,這在公司里使用自然是不行的。也有第三方的插件可用。但 ...
  • 1、數字格式化 JS版-直接寫到原型鏈上 /** * @author: silencetea * @name: * @description: 數字格式化,預設每三位用英文逗號分隔 * @param {number} number 要格式化的數字 * @param {number} decimals ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...