好的,所以在经历了很多压力和咖啡之后,我提出了这段代码,通过将鼠标悬停在链接上来显示对子元素的一些反弹效果。并且在将鼠标从链接上移开时,子元素会在延迟 4 秒后隐藏。引入这个 4 秒延迟是因为在将鼠标悬停在链接上之后,人们往往会立即将鼠标悬停在下拉菜单上,并且由于反弹效果,在和
HTML 代码:
<div id="menu">
<ul class="menu" id="tempMenu">
<li class="listOfNumbers">
<a id="Menus" href="">Numbers</a>
<ul class="submenu">
<li>
<a id="one" href="">one</a>
</li>
<li>
<a id="two" href="">two</a>
</li>
<li>
<a id="three" href="">three</a>
</li>
<li>
<a id="four" href="">four</a>
</li>
<li>
<a id="five" href="">five</a>
</li>
<li>
<a id="six" href="">six</a>
</li>
<li>
<a id="seven" href="">seven</a>
</li>
<li>
<a id="eight" href="">eight</a>
</li>
</ul>
</li>
</ul>
</div>
CSS 代码
ul { margin:0; padding:0; width:0; }
ul li {
height: 30px;
line-height: 30px;
list-style: none;
}
ul.menu li a {
padding:0;
width:90px;
display:block;
color: #fff;
font-size: 12px;
font-weight: bolder;
text-shadow: #000 0 -1px 1px;
text-decoration: none;
text-align: center;
border-top: 1px solid #666;
border-left: 1px solid #666;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
box-shadow: white 7px 5px 20px; /* W3 Standarts */
-o-box-shadow: white 7px 5px 20px; /* Opera */
-ms-box-shadow: white 7px 5px 20px; /* IE 10+ */
-moz-box-shadow: white 7px 5px 20px; /* Firefox */
-webkit-box-shadow:white 7px 5px 20px; /* Webkit */
transition: text-shadow .7s ease-out,
background .7s ease-out; /* W3 Standarts */
-o-transition: text-shadow .7s ease-out,
background .7s ease-out; /* Opera */
-ms-transition: text-shadow .7s ease-out,
background .7s ease-out; /* IE 10+ */
-moz-transition: text-shadow .7s ease-out,
background .7s ease-out; /* Firefox */
-webkit-transition: text-shadow .7s ease-out,
background .7s ease-out; /* Webkit */
background: linear-gradient(to bottom, rgba(76,76,76,1) 0%,rgba(89,89,89,1) 12%,rgba(102,102,102,1) 25%,rgba(71,71,71,1) 39%,rgba(17,17,17,1) 60%,rgba(0,0,0,1) 77%,rgba(19,19,19,1) 91%);
background: -moz-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(17,17,17,1) 60%, rgba(0,0,0,1) 77%, rgba(19,19,19,1) 91%);
/* Webkit */
background: #666 -webkit-gradient( linear, left bottom, left top, color-stop(0.3, rgb(00,00,00)), color-stop(0.9, rgb(80,80,80)) );
/* Opera */
background: #666 -o-gradient( linear, left bottom, left top, color-stop(0.3, rgb(00,00,00)), color-stop(0.9, rgb(80,80,80)) );
/* IE 10+ */
background: -ms-linear-gradient(top, rgba(76,76,76,1) 0%,rgba(89,89,89,1) 12%,rgba(102,102,102,1) 25%,rgba(71,71,71,1) 39%,rgba(17,17,17,1) 60%,rgba(0,0,0,1) 77%,rgba(19,19,19,1) 91%);
/* IE6-9 */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
}
ul.menu .listOfNumbers {
margin:15px 0 0 20px;
}
ul.menu li .submenu {
top:30px;
visibility:hidden;
}
ul.menu li:hover .submenu {
visibility:visible;
animation:mymove 1.2s linear; /* W3 Standart */
-o-animation:mymove 1.2s linear; /* Opera */
-ms-animation:mymove 1.2s linear; /* IE 10+ */
-moz-animation:mymove 1.2s linear; /* Firefox */
-webkit-animation:mymove 1.2s linear; /* Safari and Chrome */
}
ul.menu li:not(:hover) .submenu {
top:30px;
opacity:0;
transition:opacity 1.2s linear 3s,
visibility 1.2s linear 3s; /* W3 Standart */
-o-transition:opacity 1.2s linear 3s,
visibility 1.2s linear 3s; /* Opera */
-ms-transition:opacity 1.2s linear 3s,
visibility 1.2s linear 3s; /* IE 10+ */
-moz-transition:opacity 1.2s linear 3s,
visibility 1.2s linear 3s; /* Firefox */
-webkit-transition:opacity 1.2s linear 3s,
visibility 1.2s linear 3s; /* Safari and Chrome */
}
@keyframes mymove
{
0% {opacity:0.1;margin-top:0px;}
10% {opacity:0.3;margin-top:25px;}
30% {opacity:0.4;margin-top:50px;}
60% {opacity:0.5;margin-top:25px;}
80% {opacity:0.7;margin-top:50px;}
90% {opacity:0.9;margin-top:35px;}
95% {opacity:0.95;margin-top:25px;}
100% {opacity:1;margin-top:0px;}
}
/* Opera */
@-o-keyframes mymove
{
0% {opacity:0.1;margin-top:0px;}
10% {opacity:0.3;margin-top:25px;}
30% {opacity:0.4;margin-top:50px;}
60% {opacity:0.5;margin-top:25px;}
80% {opacity:0.7;margin-top:50px;}
90% {opacity:0.9;margin-top:35px;}
95% {opacity:0.95;margin-top:25px;}
100% {opacity:1;margin-top:0px;}
}
/* IE 10+ */
@-ms-keyframes mymove
{
0% {opacity:0.1;margin-top:0px;}
10% {opacity:0.3;margin-top:25px;}
30% {opacity:0.4;margin-top:50px;}
60% {opacity:0.5;margin-top:25px;}
80% {opacity:0.7;margin-top:50px;}
90% {opacity:0.9;margin-top:35px;}
95% {opacity:0.95;margin-top:25px;}
100% {opacity:1;margin-top:0px;}
}
/* Firefox */
@-moz-keyframes mymove
{
0% {opacity:0.1;margin-top:0px;}
10% {opacity:0.3;margin-top:25px;}
30% {opacity:0.4;margin-top:50px;}
60% {opacity:0.5;margin-top:25px;}
80% {opacity:0.7;margin-top:50px;}
90% {opacity:0.9;margin-top:35px;}
95% {opacity:0.95;margin-top:25px;}
100% {opacity:1;margin-top:0px;}
}
/* Safari and Chrome */
@-webkit-keyframes mymove
{
0% {opacity:0.1;margin-top:0px;}
10% {opacity:0.3;margin-top:25px;}
30% {opacity:0.4;margin-top:50px;}
60% {opacity:0.5;margin-top:25px;}
80% {opacity:0.7;margin-top:50px;}
90% {opacity:0.9;margin-top:35px;}
95% {opacity:0.95;margin-top:25px;}
100% {opacity:1;margin-top:0px;}
}
ul.menu .submenu li a {
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
/* margin: 68px 95px; */
z-index: 1000;
}
ul.menu .submenu li:first-child a {
-webkit-border-top-left-radius:10px;
-webkit-border-bottom-left-radius:2px;
-webkit-border-top-right-radius:10px;
-webkit-border-bottom-right-radius:2px;
-moz-border-top-left-radius: 10px;
-moz-border-radius-bottomleft:2px;
-moz-border-top-right-radius: 10px;
-moz-border-radius-bottomright: 2px;
border-top-left-radius: 10px;
border-bottom-left-radius:2px;
border-top-right-radius: 10px;
border-bottom-right-radius:2px;
/* margin: 34px 95px; */
z-index: 1000;
}
ul.menu .submenu li:last-child a {
-webkit-border-top-left-radius:2px;
-webkit-border-bottom-left-radius:10px;
-webkit-border-top-right-radius:2px;
-webkit-border-bottom-right-radius:10px;
-moz-border-top-left-radius: 2px;
-moz-border-radius-bottomleft:10px;
-moz-border-top-right-radius: 2px;
-moz-border-radius-bottomright: 10px;
border-top-left-radius: 2px;
border-bottom-left-radius:10px;
border-top-right-radius: 2px;
border-bottom-right-radius:10px;
/* margin:260px 95px; */
z-index: 1000;
}