行,所以我已經創建了一個顯示在盤旋在它的菜單按鈕的CSS過渡。只要鼠標移離按鈕,菜單就會隱藏起來。這是完美的,但是當我將鼠標移動到菜單本身時,菜單不應該消失。這也正在發生,但我創建了一個反彈效果使用CSS來使它更時尚,如果我嘗試在動畫發生之前將鼠標懸停在菜單上,菜單會再次隱藏,因爲菜單之間的差距和按鈕,所以我想延遲隱藏2秒,這樣即使有人按了按鈕並嘗試移動菜單,它也應該至少等待2秒,然後才能消失。 Link to fiddle延遲2秒
HTML代碼
<div id="menu">
<ul class="menu" id="tempMenu">
<li class="listOfNumbers"><a id="Menus" href="">Numbers</a><div>
<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>
</div>
</li>
</ul>
</div>
CSS代碼:
ul.menu .listOfNumbers{
position: fixed;
margin-left: 20px;
list-style-type: none;
margin: 15px 0;
float: left;
height: 30px;
line-height: 30px;
}
ul.menu .listOfNumbers a{
position: fixed;
margin-left: 93px;
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)));
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%);
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%); /* IE10+ */
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%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0); /* IE6-9 */
display: block;
padding: 0;
text-decoration: none;
color: #fff;
font-size: 12px;
font-weight: bolder;
text-shadow: #000 0 -1px 1px;
width: 90px;
text-align: center;
border-bottom: 1px solid #000;
border-top: 1px solid #666;
border-left: 1px solid #666;
border-right: 1px solid #000;
-webkit-transition:text-shadow .7s ease-out, background .7s ease-out;
-moz-transition: text-shadow .7s ease-out, background .7s ease-out;
-moz-box-shadow: white 7px 5px 20px;
-webkit-box-shadow:white 7px 5px 20px;
box-shadow: white 7px 5px 20px;
}
ul.menu .submenu{
display: none;
top: -30px;
position: absolute;
opacity: 0;
}
ul.menu .submenu li{
list-style-type: none;
}
ul.menu li:hover .submenu{
display: block;
top: -2px;
opacity: 1;
animation:mymove 1.2s linear;
-moz-animation:mymove 1.2s linear; /* Firefox */
-webkit-animation:mymove 1.2s linear; /* Safari and Chrome */
-o-animation:mymove 1.2s linear; /* Opera */
-ms-animation:mymove 1.2s linear; /* IE */
}
@keyframes mymove
{
0% {top:-10px;opacity:0.1;}
10% {top:3px;opacity:0.3;}
30% {top:40px;opacity:0.4;}
60% {top:-5px;opacity:0.5;}
80% {top:20px;opacity:0.7;}
90% {top:10px;opacity:0.9;}
95% {top:5px;opacity:0.95;}
100% {top:3px;opacity:1;}
}
@-moz-keyframes mymove /* Firefox */
{
0% {top:-10px;opacity:0.1;}
10% {top:3px;opacity:0.3;}
30% {top:40px;opacity:0.4;}
60% {top:-5px;opacity:0.5;}
80% {top:20px;opacity:0.7;}
90% {top:10px;opacity:0.9;}
95% {top:5px;opacity:0.95;}
100% {top:3px;opacity:1;}
}
@-webkit-keyframes mymove /* Safari and Chrome */
{
0% {top:-10px;opacity:0.1;}
10% {top:3px;opacity:0.3;}
30% {top:40px;opacity:0.4;}
60% {top:-5px;opacity:0.5;}
80% {top:20px;opacity:0.7;}
90% {top:10px;opacity:0.9;}
95% {top:5px;opacity:0.95;}
100% {top:3px;opacity:1;}
}
@-o-keyframes mymove /* Opera */
{
0% {top:-10px;opacity:0.1;}
10% {top:3px;opacity:0.3;}
30% {top:40px;opacity:0.4;}
60% {top:-5px;opacity:0.5;}
80% {top:20px;opacity:0.7;}
90% {top:10px;opacity:0.9;}
95% {top:5px;opacity:0.95;}
100% {top:3px;opacity:1;}
}
@-ms-keyframes mymove /* IE */
{
0% {top:-10px;opacity:0.1;}
10% {top:3px;opacity:0.3;}
30% {top:40px;opacity:0.4;}
60% {top:-5px;opacity:0.5;}
80% {top:20px;opacity:0.7;}
90% {top:10px;opacity:0.9;}
95% {top:5px;opacity:0.95;}
100% {top:3px;opacity:1;}
}
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;
-moz-border-top-left-radius: 2px;
-moz-border-radius-bottomleft:10px;
-webkit-border-top-right-radius:2px;
-webkit-border-bottom-right-radius: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;
}
ul.menu .submenu li:nth-of-type(2) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 68px 95px;
z-index: 1000;
}
ul.menu .submenu li:nth-of-type(3) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 100px 95px;
z-index: 1000;
}
ul.menu .submenu li:nth-of-type(4) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 133px 95px;
z-index: 1000;
}
ul.menu .submenu li:nth-of-type(5) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 165px 95px;
z-index: 1000;
}
ul.menu .submenu li:nth-of-type(6) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 197px 95px;
z-index: 1000;
}
ul.menu .submenu li:nth-of-type(7) a{
-webkit-border-top-left-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-top-left-radius: 0px;
-moz-border-radius-bottomleft:0px;
-webkit-border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-top-right-radius: 0px;
-moz-border-radius-bottomright: 0px;
margin: 229px 95px;
z-index: 1000;
}
我不知道是否有必要涉及JavaScript或jQuery的。但是,如果使用它們中的任何一個都可以實現,那麼它也沒問題。
我覺得你的子菜單的頂部應爲重疊的一些像素的主菜單按鈕(這是完成anmimation的情況下)。 此外,你應該表現出('顯示:block')的動畫的子菜單包裝(說父'div' ul.submenu'的'),做動畫(上說'ul.submenu')無論知名度。所以包裝將不會被隱藏,因爲您將鼠標移出「敏感」區域。 –
@ try-catch-finally是的,這聽起來像個好主意。謝謝。 –
動畫應該啓動:當然懸停(但獨立於包裝可見性)。 –