首先,您的动画非常慢,只有 40 秒。其次,您需要包含所有供应商前缀版本的关键帧。你只是忘记了-webkit
关键帧。
注意:不需要 jquery/javascript
如果您希望箭头在取消悬停后顺利返回,只需添加transition
其供应商前缀伙伴
编辑:似乎你想要在悬停时来回平滑,而不仅仅是在一个方向上平滑连续。完全相同的概念只是更改关键帧:
a {
background-position: 90% center;
-webkit-transition: background-position 0.3s linear; /* Chrome 1-25, Safari 3.2+ */
-moz-transition: background-position 0.3s linear; /* Firefox 4-15 */
-o-transition: background-position 0.3s linear; /* Opera 10.50–12.00 */
transition: background-position 0.3s linear; /* Chrome 26, Firefox 16+, IE 10+, Opera 12.10+ */
}
a:hover {
background-position: 100% center;
-moz-animation: animatedBackground 2s infinite linear;
-o-animation: animatedBackground 2s infinite linear;
-webkit-animation: animatedBackground 2s infinite linear;
animation: animatedBackground 2s infinite linear;
}
@-moz-keyframes animatedBackground {
0% {
background-position: 90% center;
}
50% {
background-position: 100% center;
}
100% {
background-position: 90% center;
}
}
@-webkit-keyframes animatedBackground {
0% {
background-position: 90% center;
}
50% {
background-position: 100% center;
}
100% {
background-position: 90% center;
}
}
@-o-keyframes animatedBackground {
0% {
background-position: 90% center;
}
50% {
background-position: 100% center;
}
100% {
background-position: 90% center;
}
}
@-ms-keyframes animatedBackground {
0% {
background-position: 90% center;
}
50% {
background-position: 100% center;
}
100% {
background-position: 90% center;
}
}
@keyframes animatedBackground {
0% {
background-position: 90% center;
}
50% {
background-position: 100% center;
}
100% {
background-position: 90% center;
}
}
这是连续(向右)箭头版本:
a {
background-position: 90% center;
-webkit-transition: background-position 0.3s linear; /* Chrome 1-25, Safari 3.2+ */
-moz-transition: background-position 0.3s linear; /* Firefox 4-15 */
-o-transition: background-position 0.3s linear; /* Opera 10.50–12.00 */
transition: background-position 0.3s linear; /* Chrome 26, Firefox 16+, IE 10+, Opera 12.10+ */
}
a:hover {
background-position: 100% center;
-moz-animation: animatedBackground 2s infinite linear;
-o-animation: animatedBackground 2s infinite linear;
-webkit-animation: animatedBackground 2s infinite linear;
animation: animatedBackground 2s infinite linear;
}
@-moz-keyframes animatedBackground {
0% {
background-position: 90% center;
}
100% {
background-position: 100% center;
}
}
@-webkit-keyframes animatedBackground {
0% {
background-position: 90% center;
}
100% {
background-position: 100% center;
}
}
@-o-keyframes animatedBackground {
0% {
background-position: 90% center;
}
100% {
background-position: 100% center;
}
}
@-ms-keyframes animatedBackground {
0% {
background-position: 90% center;
}
100% {
background-position: 100% center;
}
}
@keyframes animatedBackground {
0% {
background-position: 90% center;
}
100% {
background-position: 100% center;
}
}