css - CSS 过渡计时函数和动画名称
问题描述
我想在页面加载后添加带有贝塞尔曲线的过渡定时功能。我有一个代码,它在悬停时可以正常工作,但我希望自动获得相同的效果。所以我使用了动画名称。但贝塞尔曲线效应似乎不起作用。不过,它在悬停时工作得很好。
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width .6s;
transition-timing-function: cubic-bezier(0.87, 0, 0.13, 1);
animation: mymove .6s;
}
@keyframes mymove {
from {
transform: translate(0px, 400px);
}
to {
transform: translate(0px, 0px);
}
}
div:hover {
width:300px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
解决方案
过渡和动画是 css 中的不同属性。动画有自己的定时功能。更多信息可以参考w3school。
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width .6s;
transition-timing-function: cubic-bezier(0.87, 0, 0.13, 1);
animation: mymove 2s;
animation-timing-function: cubic-bezier(0.87, 0, 0.13, 1);
}
@keyframes mymove {
from {
transform: translate(0px, 400px);
}
to {
transform: translate(0px, 0px);
}
}
div:hover {
width:300px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
推荐阅读
- python - 有没有办法更改熊猫数据透视表的边距“全部”列位置?
- yaml - yaml 格式的木偶螺栓计划
- git - 当我写 git commit -m "Complete chapter 1" 它不工作
- reactjs - 如何在 react-leaflet 中使用 setRotationAngle
- internet-explorer - X-UA 兼容 IE=10 不能在 EDGE 上运行
- c++ - linux“重命名”函数调用是否阻塞直到复制(当源和目标在不同磁盘中时)完成
- jquery - 用于 jquery .load() 的 BeforeSend
- json - 当我将以下脚本与 selenium 和 Beautifulsoup 一起使用时,文本被正确提取,但 json 文件始终相同
- angular - 在 ng2-charts 中定义工具提示的新位置
- android - 无法从 CursorWindow 读取行。从图库中旋转图像时出错