html - 如何使两个属性具有不同持续时间的动画

标签 html css css-animations

我有一个动画 div,我为 2 个属性 right:100pxbottom:80px 设置了动画。

jsfiddle

像这样;

.demo{
    background: url(http://www.clipartbest.com/cliparts/dT7/eoj/dT7eojnT9.jpeg) no-repeat;
    height: 100px;
    width:90px;
    animation: smileDog 3s ease-in-out infinite;
    position: absolute;
    background-size:100%
}
@keyframes smileDog{
    from{right:0px;bottom: 0px;}
    to{right:100px;bottom: 80px;}
}

现在我的问题是,我可以在单个关键帧中管理动画时间吗?我的意思是 right:100px 应该在 3 秒内移动,bottom:80px 应该在 10 秒内移动。这两个 Action 应该同时开始和发生,但持续时间不同。 这可能吗?

如果不行那我该怎么做呢?

最佳答案

那么您需要 2 个关键帧:

.demo{
    background: url(http://www.clipartbest.com/cliparts/dT7/eoj/dT7eojnT9.jpeg) no-repeat;
    height: 100px;
    width:90px;
    animation: smileDogRight 3s ease-in-out infinite,
               smileDogBottom 10s ease-in-out infinite;
    position: absolute;
    background-size:100%
}
@keyframes smileDogRight{
    from{right:0px;}
    to{right:100px;}
}
@keyframes smileDogBottom{
    from{bottom: 0px;}
    to{bottom: 80px;}
}

关于html - 如何使两个属性具有不同持续时间的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26314773/

相关文章:

html - @font-face 根本不工作

javascript - 如何使用 JS 从 CSS 属性获取默认值?

javascript - CSS3 关键帧 - 更改动画持续时间会导致 "jumps"

html - 悬停时强制结束 CSS 过渡

php - 将 PHP 变量插入到 Html5 "Placeholder"属性中

javascript - Webpack - 使用不同的 javascript 脚本文件生成多个 HTML 文件

css - 转换时文本模糊 :rotate in Chrome

html - 将鼠标悬停在按钮上时如何显示文本列表?

html - 溢出:隐藏不适用于完整的视口(viewport)部分

css - 悬停动画淡入不透明度 0.5 悬停不透明度 1