css - Perspective not working on "to" transitions, but working on "back" transitions in Safari
问题描述
I've discovered this rather strange behavior of perspective
in Safari. When using perspective
on a transform: rotateY(180deg)
, the to rotation does not have the perspective applied, but the back rotation does. See the two gifs below:
Behavior on Safari. The first rotation does not have any perspective:
Compared to Firefox, where all rotations have the perspective applied:
The videos as an imgur album in case of problems with the gifs
I am using this piece of SCSS code:
.card {
perspective: 150rem;
-moz-perspective: 150rem;
&__side {
background-color: orangered;
color: white;
font-size: 2rem;
height: 50rem;
transition: all .4s;
}
&:hover &__side {
transform: rotateY(180deg);
}
}
I've already tried numerous slight changes like using -webkit-perspective
but with no success.
Here is a codepen containing the code: https://codepen.io/YellowTech/pen/rNmXemj
Am I overlooking something or how can this be fixed?
Thank you!
解决方案
The animation is trying to transform to a rotation of 180deg, but on Safari it seems to want to know what it is transforming from. Perhaps other browsers assume an initial rotation of 0deg.
I can see perspective in action if the initial condition is set:
.cont {
width: 300px;
}
.card {
perspective: 150rem;
-moz-perspective: 150rem;
&__side {
background-color: orangered;
color: white;
font-size: 2rem;
height: 50rem;
transition: all .4s;
transform: rotateY(0deg); /* ADDED */
}
&:hover &__side {
transform: rotateY(180deg);
}
}
推荐阅读
- mongodb - $group 后的 $lookup 嵌套外部 id
- f# - 这是在 F# 中正确使用 match with 还是有更惯用的方法来完成相同的操作
- c# - 为什么我收到错误“找不到文件'C\Users\daylo\Onedrive\Desktop\VisualStudio\Total Sales\Total Sales\bin\Debug\Sales/txt'
- .htaccess - Htaccess 301 重定向只是重定向域而不是页面
- android-studio - Flutter SQFlite:使用数据库内容更新列表视图时遇到问题
- java - 我如何设置 Apache Shiro 会话
- django - 序列化多对多字段 drf haystack
- vba - 将交叉引用链接插入表格单元格
- python - Python用从索引到另一个的值填充数组
- c++ - 用袖带实现实到复 FFT