欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一款纯css3实现的动画加载导航

程序员文章站 2022-03-30 11:28:09
这篇文章主要为大家介绍了用css3实现的动画加载导航,该导航出现的时候以动画的形式出现,下面请和脚本之家的小编一起来学习一下... 14-10-08...

今天为给大家再带来一款纯css3实现的动画加载导航。该导航出现的时候以动画的形式出现。效果图如下:

html代码:


复制代码
代码如下:
<ul class="main-menu">
<li class="main-menu-item active"><a href="#">home</a></li><li class="main-menu-item">
<a href="#">about us</a></li><li class="main-menu-item"><a href="#">another link</a></li><li
class="main-menu-item"><a href="#">and another</a></li><li class="main-menu-item"><a
href="#">stuff</a></li><li class="main-menu-item"><a href="#">help</a></li><li class="main-menu-item">
<a href="#">contact</a></li></ul>

css代码:


复制代码
代码如下:
*, *:after, *:before {
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
background: #f0f0f0;
font-family: helvetica, sans-serif;
height: 100%;
}
.main-menu {
margin: auto;
width: 960px;
text-align: center;
position: relative;
list-style-type: none;
margin-top: 2em;
}
.main-menu::after,
.main-menu-item.active::after {
content: '';
display: inline-block;
position: absolute;
}
.main-menu::after {
width: 70%;
height: 2px;
background: #9b1c27;
-webkit-animation: menuline 1s ease forwards;
animation: menuline 1s ease forwards;
-webkit-transform: scalex(0);
-ms-transform: scalex(0);
transform: scalex(0);
bottom: 0;
left: 0;
right: 0;
margin: auto;
opacity: 0;
}
@-webkit-keyframes menuline {
to {
-webkit-transform: scalex(1);
transform: scalex(1);
opacity: 1;
}
}
@keyframes menuline {
to {
-webkit-transform: scalex(1);
transform: scalex(1);
opacity: 1;
}
}
@-webkit-keyframes menuitem {
to {
-webkit-transform: translatey(0);
transform: translatey(0);
opacity: 1;
}
}
@keyframes menuitem {
to {
-webkit-transform: translatey(0);
transform: translatey(0);
opacity: 1;
}
}
.main-menu-item a {
display: block;
padding: 1em;
text-decoration: none;
color: #555;
opacity: 0;
-webkit-transform: translatey(40%);
-ms-transform: translatey(40%);
transform: translatey(40%);
-webkit-animation: menuitem .8s ease forwards;
animation: menuitem .8s ease forwards;
-webkit-transition: all .2s ease;
transition: all .2s ease;
}
.main-menu-item:nth-child(4) a {
-webkit-animation-delay: .4s;
animation-delay: .4s;
}
.main-menu-item:nth-child(3) a, .main-menu-item:nth-child(5) a {
-webkit-animation-delay: .5s;
animation-delay: .5s;
}
.main-menu-item:nth-child(2) a, .main-menu-item:nth-child(6) a {
-webkit-animation-delay: .6s;
animation-delay: .6s;
}
.main-menu-item:nth-child(1) a, .main-menu-item:nth-child(7) a {
-webkit-animation-delay: .7s;
animation-delay: .7s;
}
.main-menu-item {
display: inline-block;
position: relative;
}
.main-menu-item:hover a, .main-menu-item.active {
color: #9b1c27;
}
.main-menu-item:hover a::after, .main-menu-item.active::after {
width: 0;
height: 0;
border-bottom: .5em solid #9b1c27;
border-left: .5em solid transparent;
border-right: .5em solid transparent;
bottom: 0;
left: 0;
right: 0;
margin: auto;
opacity: 0;
-webkit-transform: translatey(0.05em);
-ms-transform: translatey(0.05em);
transform: translatey(0.05em);
-webkit-animation: menuitem .8s 1.2s ease forwards;
animation: menuitem .8s 1.2s ease forwards;
}