css - 带有 transform rotateX 的 CSS 错误有时会旋转太多
问题描述
在这里你可以看到我在说什么:
.layout{
width: 600px;
background-color: #211d1d;
box-shadow: inset 0 0 24px 9px black;
display: inline-flex;
}
.square-container{
position: relative;
width: 300px;
height: 260px;
}
.square {
position: absolute;
width: 260px;
height: 210px;
top: 20px;
left: 20px;
border: 1px solid black;
color: white;
background: rgb(51, 51, 101);
background: linear-gradient(
153deg,
rgba(51, 51, 101, 0.9) 0%,
rgba(0, 212, 255, 0.3) 100%
);
transition-duration: 0.1s;
// transition-delay: 0.1s; //helps but not radically
}
.square-container:hover>.square{
transform: scale(1.06) perspective(10rem) rotateX(-1deg);
}
<div class="layout">
<div class="square-container">
<div class="square">Switch your mouse back annd forth really really fast between me</div>
</div>
<div class="square-container">
<div class="square">and me and you'll see one of us sometimes spin crazily</div>
<div>
</div>
悬停应该是什么样子:
短暂的悬停有时看起来像(错误):
(有时效果被夸大得多)
是什么原因造成的,我该如何预防?
解决方案
这是因为您正在为视角设置动画。为了避免这种情况,使悬停/取消悬停状态之间的透视相同,并且仅更改其他变换值:
.layout {
width: 600px;
background-color: #211d1d;
box-shadow: inset 0 0 24px 9px black;
display: inline-flex;
}
.square-container {
position: relative;
width: 300px;
height: 260px;
}
.square {
position: absolute;
width: 260px;
height: 210px;
top: 20px;
left: 20px;
border: 1px solid black;
color: white;
background: rgb(51, 51, 101);
background: linear-gradient( 153deg, rgba(51, 51, 101, 0.9) 0%, rgba(0, 212, 255, 0.3) 100%);
transition-duration: 0.1s;
transform: scale(1) perspective(10rem) rotateX(0);
}
.square-container:hover>.square {
transform: scale(1.06) perspective(10rem) rotateX(-1deg);
}
<div class="layout">
<div class="square-container">
<div class="square">Switch your mouse back annd forth really really fast between me</div>
</div>
<div class="square-container">
<div class="square">and me and you'll see one of us sometimes spin crazily</div>
</div>
</div>
推荐阅读
- c - struct* 赋值语句显示警告
- python - 将多列上的 groupby 结果转换为字典列表
- ios - 有没有一种特殊的方法可以将 ChildViewController 的成员访问到 ViewController 中,在函数 prepare(for: segue) 中使用其他方法?
- reactjs - 如何在 MaterialUi React 的 Autocomplete 中将状态转化为值
- reactjs - 如何在 React-Dropzone-Uploader 的 getUploadParams 方法中添加基本身份验证详细信息?
- python - python将unicode代码值转换为字符串,不带'\u'
- c# - 如何获取 onget 中的 ID 和 asp.net core razor 页面中的使用处理程序?
- sql-server - SQL Server 脚本到 Teradata Bteq 的转换
- java - Java 我可以将一个类导入另一个类吗?
- vim - 将这两列转置成行?