为了使用 CSS3 制作一个看起来不错的下拉菜单,我使用动画设置了样式。为了能够更好地控制下降的时间,我使用了动画而不是过渡。我觉得这样更美观。然而,在使用过渡动画时确实会遇到问题,因为反向过程变得更难制作动画。我想知道是否有办法在使用菜单时有效地暂停动画,让它反向动画,就像在过渡中一样。
这是 CSS 现在的样子:
@-webkit-keyframes s-menu-down /*Safari and Chrome */ {
0% { width: 100%; height: 0px;}
100% { width: 180px; height: 27px;}
}
@-moz-keyframes s-menu-down /*Firefox */ {
0% { width: 100%; height: 0px;}
100% { width: 180px; height: 27px;}
}
@keyframes s-menu-down {
0% { width: 100%; height: 0px;}
100% { width: 180px; height: 27px;}
}
@-webkit-keyframes s-menu-down-text /*Safari and Chrome */ {
0% { color: rgba(84, 83, 81, .0); text-shadow: none;}
100% { color: rgba(84, 83, 81, 1.0); text-shadow: rgba(238, 238, 238, 1.0);}
}
@-moz-keyframes s-menu-down-text /*Firefox */ {
0% { color: rgba(84, 83, 81, .0); text-shadow: none;}
100% { color: rgba(84, 83, 81, 1.0); text-shadow: rgba(238, 238, 238, 1.0);}
}
@keyframes s-menu-down-text {
0% { color: rgba(84, 83, 81, .0); text-shadow: none;}
100% { color: rgba(84, 83, 81, 1.0); text-shadow: rgba(238, 238, 238, 1.0);}
}
ul#secondary li:hover > ul li {
-webkit-animation: s-menu-down .5s linear 0 2 alternate;
-moz-animation: s-menu-down .5s linear 0 2 alternate;
animation: s-menu-down .5s linear 0 2 alternate;
}
ul#secondary li:hover > ul li a {
-webkit-animation: s-menu-down-text .5s linear 0 2 alternate;
-moz-animation: s-menu-down-text .5s linear 0 2 alternate;
animation: s-menu-down-text .5s linear 0 2 alternate;
}
通过将 CSS 设置为交替,并通过重复 2,我可以使菜单上下移动。我正在寻找某种 javascript 解决方案或其他类似的解决方案,以便在迭代之间暂停以允许使用菜单。