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>