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

css3实现垂直下拉动画菜单示例

程序员文章站 2022-05-21 14:12:01
这篇文章主要介绍了css3实现垂直下拉动画菜单示例,需要的朋友可以参考下... 14-04-22...

css3实现垂直下拉动画菜单示例


复制代码
代码如下:

<nav>
<ul class="mcd-menu">
<li>
<a href="">
<i class="fa fa-home"></i>
<strong>home</strong>
<small>sweet home</small>
</a>
</li>
<li>
<a href="" class="active">
<i class="fa fa-edit"></i>
<strong>about us</strong>
<small>sweet home</small>
</a>
</li>
<li>
<a href="">
<i class="fa fa-gift"></i>
<strong>features</strong>
<small>sweet home</small>
</a>
</li>
<li>
<a href="">
<i class="fa fa-globe"></i>
<strong>news</strong>
<small>sweet home</small>
</a>
</li>
<li>
<a href="">
<i class="fa fa-comments-o"></i>
<strong>blog</strong>
<small>what they say</small>
</a>
<ul>
<li><a href="#"><i class="fa fa-globe"></i>mission</a></li>
<li>
<a href="#"><i class="fa fa-group"></i>our team</a>
<ul>
<li><a href="#"><i class="fa fa-female"></i>leyla sparks</a></li>
<li>
<a href="#"><i class="fa fa-male"></i>gleb ismailov</a>
<ul>
<li><a href="#"><i class="fa fa-leaf"></i>about</a></li>
<li><a href="#"><i class="fa fa-tasks"></i>skills</a></li>
</ul>
</li>
<li><a href="#"><i class="fa fa-female"></i>viktoria gibbers</a></li>
</ul>
</li>
<li><a href="#"><i class="fa fa-trophy"></i>rewards</a></li>
<li><a href="#"><i class="fa fa-certificate"></i>certificates</a></li>
</ul>
</li>
<li>
<a href="">
<i class="fa fa-picture-o"></i>
<strong>portfolio</strong>
<small>sweet home</small>
</a>
</li>
<li>
<a href="">
<i class="fa fa-envelope-o"></i>
<strong>contacts</strong>
<small>drop a line</small>
</a>
</li>
<li class="float">
<a class="search">
<input type="text" value="search ...">
<button><i class="fa fa-search"></i></button>
</a>
<a href="" class="search-mobile">
<i class="fa fa-search"></i>
</a>
</li>
</ul>
</nav>

这里用ul构造了菜单的基本结构。

接下来就利用css3代码来实现菜单的下拉和动画效果。

css代码比较繁琐,这里我只是提供一些核心的css代码,完整的代码大家可以在文章最后下载学习。

这是鼠标滑过菜单项时的动画代码:


复制代码
代码如下:

.mcd-menu li a i, .mcd-menu li a strong, .mcd-menu li a small {
position: relative;

transition: all 300ms linear;
-o-transition: all 300ms linear;
-ms-transition: all 300ms linear;
-moz-transition: all 300ms linear;
-webkit-transition: all 300ms linear;
}
.mcd-menu li:hover > a i {
opacity: 1;
-webkit-animation: movefromtop 300ms ease-in-out;
-moz-animation: movefromtop 300ms ease-in-out;
-ms-animation: movefromtop 300ms ease-in-out;
-o-animation: movefromtop 300ms ease-in-out;
animation: movefromtop 300ms ease-in-out;
}
.mcd-menu li:hover a strong {
opacity: 1;
-webkit-animation: movefromleft 300ms ease-in-out;
-moz-animation: movefromleft 300ms ease-in-out;
-ms-animation: movefromleft 300ms ease-in-out;
-o-animation: movefromleft 300ms ease-in-out;
animation: movefromleft 300ms ease-in-out;
}
.mcd-menu li:hover a small {
opacity: 1;
-webkit-animation: movefromright 300ms ease-in-out;
-moz-animation: movefromright 300ms ease-in-out;
-ms-animation: movefromright 300ms ease-in-out;
-o-animation: movefromright 300ms ease-in-out;
animation: movefromright 300ms ease-in-out;
}</p> <p>.mcd-menu li:hover > a {
color: #e67e22;
}

以下定义了鼠标滑过后文字图标滑过的动画,分别是从顶部划入,从左侧划入,从右侧划入:


复制代码
代码如下:

@-webkit-keyframes movefromtop {
from {
opacity: 0;
-webkit-transform: translatey(200%);
-moz-transform: translatey(200%);
-ms-transform: translatey(200%);
-o-transform: translatey(200%);
transform: translatey(200%);
}
to {
opacity: 1;
-webkit-transform: translatey(0%);
-moz-transform: translatey(0%);
-ms-transform: translatey(0%);
-o-transform: translatey(0%);
transform: translatey(0%);
}
}
@-webkit-keyframes movefromleft {
from {
opacity: 0;
-webkit-transform: translatex(200%);
-moz-transform: translatex(200%);
-ms-transform: translatex(200%);
-o-transform: translatex(200%);
transform: translatex(200%);
}
to {
opacity: 1;
-webkit-transform: translatex(0%);
-moz-transform: translatex(0%);
-ms-transform: translatex(0%);
-o-transform: translatex(0%);
transform: translatex(0%);
}
}
@-webkit-keyframes movefromright {
from {
opacity: 0;
-webkit-transform: translatex(-200%);
-moz-transform: translatex(-200%);
-ms-transform: translatex(-200%);
-o-transform: translatex(-200%);
transform: translatex(-200%);
}
to {
opacity: 1;
-webkit-transform: translatex(0%);
-moz-transform: translatex(0%);
-ms-transform: translatex(0%);
-o-transform: translatex(0%);
transform: translatex(0%);
}
}