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
  • 概述:本文代碼示例演示瞭如何在WPF中使用LiveCharts庫創建動態條形圖。通過創建數據模型、ViewModel和在XAML中使用`CartesianChart`控制項,你可以輕鬆實現圖表的數據綁定和動態更新。我將通過清晰的步驟指南包括詳細的中文註釋,幫助你快速理解並應用這一功能。 先上效果: 在 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • 概述:本示例演示了在WPF應用程式中實現多語言支持的詳細步驟。通過資源字典和數據綁定,以及使用語言管理器類,應用程式能夠在運行時動態切換語言。這種方法使得多語言支持更加靈活,便於維護,同時提供清晰的代碼結構。 在WPF中實現多語言的一種常見方法是使用資源字典和數據綁定。以下是一個詳細的步驟和示例源代 ...
  • 描述(做一個簡單的記錄): 事件(event)的本質是一個委托;(聲明一個事件: public event TestDelegate eventTest;) 委托(delegate)可以理解為一個符合某種簽名的方法類型;比如:TestDelegate委托的返回數據類型為string,參數為 int和 ...
  • 1、AOT適合場景 Aot適合工具類型的項目使用,優點禁止反編 ,第一次啟動快,業務型項目或者反射多的項目不適合用AOT AOT更新記錄: 實實在在經過實踐的AOT ORM 5.1.4.117 +支持AOT 5.1.4.123 +支持CodeFirst和非同步方法 5.1.4.129-preview1 ...
  • 總說周知,UWP 是運行在沙盒裡面的,所有許可權都有嚴格限制,和沙盒外交互也需要特殊的通道,所以從根本杜絕了 UWP 毒瘤的存在。但是實際上 UWP 只是一個應用模型,本身是沒有什麼許可權管理的,許可權管理全靠 App Container 沙盒控制,如果我們脫離了這個沙盒,UWP 就會放飛自我了。那麼有沒... ...
  • 目錄條款17:讓介面容易被正確使用,不易被誤用(Make interfaces easy to use correctly and hard to use incorrectly)限制類型和值規定能做和不能做的事提供行為一致的介面條款19:設計class猶如設計type(Treat class de ...
  • title: 從零開始:Django項目的創建與配置指南 date: 2024/5/2 18:29:33 updated: 2024/5/2 18:29:33 categories: 後端開發 tags: Django WebDev Python ORM Security Deployment Op ...
  • 1、BOM對象 BOM:Broswer object model,即瀏覽器提供我們開發者在javascript用於操作瀏覽器的對象。 1.1、window對象 視窗方法 // BOM Browser object model 瀏覽器對象模型 // js中最大的一個對象.整個瀏覽器視窗出現的所有東西都 ...