jQuery和CSS3实现带变形特效的固定导航菜单

jQuery和CSS3实现带变形特效的固定导航菜单

这是一款jQuery和CSS3带变形特效的固定导航菜单。该导航菜单开始时固定在页面左上角,当用户向下滚动时,导航菜单以水滴变形的方式转换为圆形菜单,然后固定在页面的左上角位置。

HTML结构
该导航菜单的主菜单HTML结构如下:

1
2
3
4
5
6
7
8
9
<nav>
  <div id="drop">
    <div>
      <span></span>
      <span></span>
      <span></span>
    </div>
  </div>
</nav>

然后创建全屏导航菜单。

1
2
3
4
5
6
7
<ul>
  <li>Home</li>
  <li>Portfolio</li>
  <li>Jobs</li>
  <li>Contact</li>
  <li>About</li>
</ul>

CSS样式
为导航菜单添加下面的CSS样式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#drop, nav { background-color: #f8f8f8 }
nav {
  width: 90%;
  height: 90px;
  padding: 0 5%;
  position: relative;
  justify-content: flex-start;
  align-items: center
}
   
nav~ul {
  position: absolute;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  left: 1%;
  right: 1%;
  opacity: 0;
  visibility: hidden;
  z-index: 2;
  list-style: none;
  transition: 0s
}
   
nav~ul>li {
  color: #70f;
 padding: 10px;
  cursor: pointer;
  font-size: 30px
}
   
nav~ul>li:hover { filter: brightness(200%) }
   
nav.open~ul {
  transition: .75s ease-in-out;
  visibility: visible;
  opacity: 1
}
   
#drop {
 cursor: pointer;
  position: fixed;
  width: 70px;
  height: 70px;
  border-radius: 0 50% 50%;
  transform: rotate(45deg);
  transition: border-radius .5s
}
   
nav.open>#drop {
 transition: .5s ease-in-out;
  box-shadow: 0 0 0 1000px #f8f8f8, inset 0 0 0 20px #f8f8f8;
 position: relative
}
   
#drop.active {
 border-radius: 50%;
  animation: drop .3s forwards
}
   
#drop>div {
 transform: rotate(-45deg);
  height: 100%;
  width: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center
}
   
#drop span {
 display: block;
  background-color: #70f;
 width: 40px;
  height: 3px;
  margin: 5px 0;
  transition: .5s
}
   
#drop span.open:nth-child(1) { transform: rotate(45deg) translate(5px, 5px) }
 
#drop span.open:nth-child(2) { transform: rotate(-45deg) translate(5px, -5px) }
 
#drop span.open:nth-child(3) { opacity: 0 }
 
@keyframes
drop { 0% {
transform:translateY(0) rotate(45deg)
}
50% {
transform:translateY(30px) rotate(45deg)
}
100% {
transform:translateY(10px) rotate(45deg)
}
}

文件信息:

    1

    发表评论