css - 悬停时连续的 CSS 旋转动画,悬停时动画回到 0deg

标签 css css-animations

我有一个元素,当你无限期地将鼠标悬停在它上面时它会旋转。当您悬停时,动画停止。简单:

@-webkit-keyframes rotate {
    from {
        -webkit-transform: rotate(0deg);
    }
    to { 
        -webkit-transform: rotate(360deg);
    }
}

.elem:hover {
    -webkit-animation-name: rotate; 
    -webkit-animation-duration: 1.5s; 
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
}

但是,当您悬停时,动画突然停止,恢复到 0 度。我想动画回到那个位置,但我在计算语法时遇到了一些问题。

任何输入都会很棒!

最佳答案

解决方案是在您的 .elem 中设置默认值。 但是这个动画在 -moz 上工作得很好,但还没有在 -webkit 中实现

看看我从你那里更新的 fiddle : http://jsfiddle.net/DoubleYo/4Vz63/1648/

它在 Firefox 上运行良好,但在 Chrome 上运行不佳

.elem{
    position: absolute;
    top: 40px;
    left: 40px;
    width: 0; 
    height: 0;
    border-style: solid;
    border-width: 75px;
    border-color: red blue green orange;
    transition-property: transform;
    transition-duration: 1s;
}
.elem:hover {
    animation-name: rotate; 
    animation-duration: 2s; 
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

@keyframes rotate {
    from {transform: rotate(0deg);}
    to {transform: rotate(360deg);}
}
<div class="elem"></div>

关于css - 悬停时连续的 CSS 旋转动画,悬停时动画回到 0deg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7988962/

相关文章:

CSS transform-origin center 不会按预期均匀扩展宽度或高度

javascript - 我可以转换 flex box 的 flex-grow 来生成动画吗?

jquery - 垂直滚动条在 IE 和 firefox 中不可见

html - 删除 Bootstrap 4 DataTable 滚动条会导致表格变窄

html - 使用 css 垂直集中的最佳/正确方法是什么?

css - 纯CSS移动div元素的背景图片

css3不同状态的不同关键帧

html - 在另一个没有显示的地方显示元素 : none

css - Angular 应用程序中的过渡动画在 EDGE 中不起作用

jquery - Fadein 不适用于 Opera 和 Firefox