【H5/CSS3】旋轉展開收縮菜單欄

来源:https://www.cnblogs.com/PaturNax/archive/2022/09/11/16683521.html
-Advertisement-
Play Games

1 別人寫的 地址鏈接 視頻鏈接: https://www.bilibili.com/video/BV1TK4y1Q78s github鏈接: https://github.com/Lavender-z/demo 如果上不了,就下個dev-sidecar代理 效果 代碼註釋 <!DOCTYPE ht ...


1 別人寫的

地址鏈接

視頻鏈接:
https://www.bilibili.com/video/BV1TK4y1Q78s

github鏈接:
https://github.com/Lavender-z/demo

如果上不了,就下個dev-sidecar代理

效果

代碼註釋

<!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" />
		<link
			rel="stylesheet"
			href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"
		/>

		<title>Document</title>
	</head>
	<style>
		body {
			overflow: hidden;
			background: linear-gradient(to right, #ffb95e, #f35c70);
		}

		/* 這個僅僅只是固定位置的 */
		.menu-toggler {
			position: absolute;
			display: block;
			top: 0;
			bottom: 0;
			right: 0;
			left: 0;
			margin: auto;
			width: 40px;
			height: 40px;
			z-index: 2;
			opacity: 0;
			cursor: pointer;
		}

		/* 滑鼠靠近菜單按鈕,長條就會亮成白色 */
		.menu-toggler:hover + label,
		.menu-toggler:hover + label:before,
		.menu-toggler:hover + label:after {
			background: white;
		}
		/* label確認點擊後,把中間的橫桿隱藏掉,也就是X */
		.menu-toggler:checked + label {
			background: transparent;
		}
		/* 那兩條橫杠的可以保證交叉組成X後,不會出現錯位的現象 */
		.menu-toggler:checked + label:before,
		.menu-toggler:checked + label:after {
			top: 0;
			width: 40px;
			transform-origin: 50% 50%;
		}

		/* 那兩條橫杠在點擊後就旋轉到對應的角度,然後組成X */
		.menu-toggler:checked + label:before {
			transform: rotate(45deg);
		}

		.menu-toggler:checked + label:after {
			transform: rotate(-45deg);
		}

		/* 點擊後就表示不隱藏菜單列表 */
		.menu-toggler:checked ~ ul .menu-item {
			opacity: 1;
		}

		/* transform先寫旋轉位置的角度,再寫元素離中心點的位置,那麼就能形成一個圓圈的擺放 */
		.menu-toggler:checked ~ ul .menu-item:nth-child(1) {
			transform: rotate(0deg) translateX(-110px);
		}

		.menu-toggler:checked ~ ul .menu-item:nth-child(2) {
			transform: rotate(60deg) translateX(-110px);
		}

		.menu-toggler:checked ~ ul .menu-item:nth-child(3) {
			transform: rotate(120deg) translateX(-110px);
		}

		.menu-toggler:checked ~ ul .menu-item:nth-child(4) {
			transform: rotate(180deg) translateX(-110px);
		}

		.menu-toggler:checked ~ ul .menu-item:nth-child(5) {
			transform: rotate(240deg) translateX(-110px);
		}

		.menu-toggler:checked ~ ul .menu-item:nth-child(6) {
			transform: rotate(300deg) translateX(-110px);
		}

		/* 由於每個菜單選項都是要hover後才產生效果,那麼在菜單沒展示開的時候根本不用顯示效果 */
		.menu-toggler:checked ~ ul .menu-item a {
			pointer-events: auto;
		}

		/* 畫白色橫桿的位置 */
		.menu-toggler + label {
			width: 40px;
			height: 5px;
			display: block;
			z-index: 1;
			border-radius: 2.5px;
			background: rgba(255, 255, 255, 0.7);
			transition: transform 0.5s, top 0.5s;
			position: absolute;
			top: 0;
			bottom: 0;
			right: 0;
			left: 0;
			margin: auto;
		}

		.menu-toggler + label:before,
		.menu-toggler + label:after {
			width: 40px;
			height: 5px;
			display: block;
			z-index: 1;
			border-radius: 2.5px;
			background: rgba(255, 255, 255, 0.7);
			transition: transform 0.5s, top 0.5s;
			content: '';
			position: absolute;
			left: 0;
		}

		.menu-toggler + label:before {
			top: 10px;
		}

		.menu-toggler + label:after {
			top: -10px;
		}

		/* 因為每個圖標在菜單展開時都要實現旋轉的效果,但是旋轉後的圖標會很不能擺正,所以要調回來 */
		.menu-item:nth-child(1) a {
			transform: rotate(0deg);
		}

		.menu-item:nth-child(2) a {
			transform: rotate(-60deg);
		}

		.menu-item:nth-child(3) a {
			transform: rotate(-120deg);
		}

		.menu-item:nth-child(4) a {
			transform: rotate(-180deg);
		}

		.menu-item:nth-child(5) a {
			transform: rotate(-240deg);
		}

		.menu-item:nth-child(6) a {
			transform: rotate(-300deg);
		}

		.menu-item a {
			/* 由於原來的每個圖標都很小,所以需要拉寬和拉長 */
			display: block;
			width: inherit;
			height: inherit;
			line-height: 80px;
			color: rgba(255, 255, 255, 0.7);
			background: rgba(255, 255, 255, 0.2);
			border-radius: 50%;
			text-align: center;
			text-decoration: none;
			font-size: 40px;
			pointer-events: none;
			transition: 0.2s;
		}

		.menu-item {
			position: absolute;
			display: block;
			top: 0;
			bottom: 0;
			right: 0;
			left: 0;
			margin: auto;
			width: 80px;
			height: 80px;
			/* 因為所有菜單選項都會回到中心,那麼就需要隱藏掉他們的內容 */
			opacity: 0;
			transition: 0.5s;
		}

		/* hover到圖標顯示放大的效果 */
		.menu-item a:hover {
			box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
			color: white;
			background: rgba(255, 255, 255, 0.3);
			font-size: 44.44px;
		}
	</style>
	<body>
		<!-- 菜單部分 -->
		<nav class="menu">
			<input
				checked="checked"
				class="menu-toggler"
				id="menu-toggler"
				type="checkbox"
			/>
			<label for="menu-toggler"></label>
			<ul>
				<li class="menu-item">
					<a class="fa fa-facebook" href="javascript:void(0)"></a>
				</li>
				<li class="menu-item">
					<a class="fa fa-youtube" href="javascript:void(0)"></a>
				</li>
				<li class="menu-item">
					<a class="fa fa-wordpress" href="javascript:void(0)"></a>
				</li>
				<li class="menu-item">
					<a class="fa fa-qq" href="javascript:void(0)"></a>
				</li>
				<li class="menu-item">
					<a class="fa fa-weixin" href="javascript:void(0)"></a>
				</li>
				<li class="menu-item">
					<a class="fa fa-github" href="javascript:void(0)"></a>
				</li>
			</ul>
		</nav>
	</body>
</html>

2 我這個菜雞寫的案例——上述案例plus版

效果

代碼

<!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>Document</title>
	</head>
	<style>
		/* 基本配置 */
		* {
			padding: 0px;
			margin: 0px;
		}
		body {
			display: flex;
			align-items: center;
			align-content: center;
			justify-content: space-around;
			background-color: #eceff1;
		}
		.container {
			margin-top: 70px;
			width: 500px;
			height: 500px;
			position: relative;
		}
		/* 設置基本樣式 */
		.circle {
			width: 70px;
			height: 70px;
			background-color: #f9403d;
			border-radius: 50%;

			display: flex;
			text-align: center;
			justify-content: center;
			align-content: center;
			align-items: center;
			position: absolute;
			bottom: 10px;
			left: 10px;
		}

		.circle img {
			width: 75%;
		}

		.items li {
			width: 70px;
			height: 70px;
			background-color: #f9403d;
			border-radius: 50%;
			display: flex;
			text-align: center;
			position: absolute;
			bottom: 10px;
			left: 10px;
			z-index: -1;
			display: block;
			transition: 1s;
		}

		li img {
			width: 75%;
			margin-top: 8px;
		}

		/* 這是通過過渡實現的效果 */
		#menu:not(:checked) ~ .items li:nth-child(1) {
			transform: rotate(0deg) translateY(-110px);
		}
		#menu:not(:checked) ~ .items li:nth-child(2) {
			transform: rotate(60deg) translateY(-110px);
		}
		#menu:not(:checked) ~ .items li:nth-child(3) {
			transform: rotate(120deg) translateY(-110px);
		}
		#menu:not(:checked) ~ .items li:nth-child(4) {
			transform: rotate(180deg) translateY(-110px);
		}
		#menu:not(:checked) ~ .items li:nth-child(5) {
			transform: rotate(240deg) translateY(-110px);
		}
		#menu:not(:checked) ~ .items li:nth-child(6) {
			transform: rotate(300deg) translateY(-110px);
		}

		.items li:nth-child(1) img {
			transform: rotate(-90deg);
		}
		.items li:nth-child(2) img {
			transform: rotate(-150deg);
		}
		.items li:nth-child(3) img {
			transform: rotate(-210deg);
		}
		.items li:nth-child(4) img {
			transform: rotate(-270deg);
		}
		.items li:nth-child(5) img {
			transform: rotate(-330deg);
		}
		.items li:nth-child(6) img {
			transform: rotate(-390deg);
		}

		#menu:not(:checked) ~ label .circle {
			animation-name: disappear;
			animation-duration: 180.5ms;
			animation-iteration-count: 1;
			animation-fill-mode: forwards;
		}

		@keyframes disappear {
			0% {
				transform: scale(1);
			}
			50% {
				transform: scale(1.2);
			}
			100% {
				transform: scale(0.85) rotate(-45deg);
			}
		}

		#menu:checked ~ label .circle {
			animation-name: appear;
			animation-duration: 0.5ms;
			animation-iteration-count: 1;
			animation-fill-mode: forwards;
		}

		#menu:checked ~ label .circle:hover {
			width: 80px;
			height: 80px;
			bottom: 5px;
			left: 5px;
		}

		@keyframes appear {
			0% {
				transform: scale(0.85) rotate(45deg);
			}
			50% {
				transform: scale(1.2);
			}
			100% {
				transform: scale(1);
			}
		}
	</style>
	<body>
		<div class="container">
			<input type="checkbox" id="menu" checked="checked" />
			<label for="menu">
				<div class="circle">
					<img src="./img/plus.png" alt="" />
				</div>
			</label>
			<ul class="items">
				<li><img src="./img/plus.png" alt="" /></li>
				<li><img src="./img/plus.png" alt="" /></li>
				<li><img src="./img/plus.png" alt="" /></li>
				<li><img src="./img/plus.png" alt="" /></li>
				<li><img src="./img/plus.png" alt="" /></li>
				<li><img src="./img/plus.png" alt="" /></li>
			</ul>
		</div>
	</body>
</html>


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

-Advertisement-
Play Games
更多相關文章
  • 0. 前言 可以臨時設置,也可以修改配置文件 1. 修改配置文件 # 打開 配置IP的文件 路徑如下 sudo vi /etc/netplan/01-network-manager-all.yaml 1.1 輸入(修改)以下內容 # This is the network config writte ...
  • MySQL架構: 採用C/S架構,即客戶端/伺服器。客戶端和伺服器區分開,通過客戶端發送請求來和伺服器交互。 過程: 用戶通過開發的應用程式來訪問資料庫(C/S),應用程式通過連接器(connecter)連接到資料庫。 連接器包含了各種開發語言的介面,連接完成後MySQL會分配一個線程提供服務,執行 ...
  • MySQL異常sql_mode=only_full_group_by 原因:在MySQL 5.7後MySQL預設開啟了SQL_MODE嚴格模式,對數據進行嚴格校驗。會報sql_mode=only_full_group_by錯誤說明寫的SQL語句不嚴謹,對於group by聚合操作,select中的列 ...
  • 原文鏈接:https://juejin.cn/post/7139572163371073543 項目準備 代碼、手冊 本文對應 2022 年的課程,Project 0 已經更新為實現字典樹了。C++17 的開發環境建議直接下載 CLion,不建議自己瞎折騰。 測試 $ mkdir build && ...
  • MySQL學習筆記 數據結構圖 更改字元集 alter database dbName character set 'charsetName'; alter database dwg2pdf character set 'utf8'; alter table tableName convert to ...
  • MySQL的用戶賬號: 由兩部分組成:用戶名和主機名 格式:'user_name'@'host' host必須要用引號括起來 註意:host可以是一個主機名也可以是具體的ip地址、網段等。 當host為主機名時: #例如: user1@'web1.redhat.org' 當host是ip地址或者網段 ...
  • 介紹弱隔離級別 為什麼要有弱隔離級別 如果兩個事務操作的是不同的數據, 即不存在數據依賴關係, 則它們可以安全地並行執行。但是當出現某個事務修改數據而另一個事務同時要讀取該數據, 或者兩個事務同時修改相同數據時, 就會出現併發問題。 在應用程式的開發中,我們通常會利用鎖進行併發控制,確保臨界區的資源 ...
  • 第一篇博客:HTML:iframe簡要介紹 前端 我們在寫網頁的時間,有許多重覆的界面,樣式和設計都一模一樣,為了避免代碼冗餘,我們通常把那些界面重覆的寫一個網頁,然後在需要的網頁進行引用那些重覆的界面,這時就需用到iframe。 1、iframe 定義和用法 : 1.iframe一般用來包含別的頁 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...