为元素设置width
and并将其用于悬停而不是元素:height
.box
.rotateaux
.box {
position: relative;
width: 50px;
height: 90px;
...
}
.box:hover .rotateaux {
有趣的是,当使用rotate3d
Firefox 时,只要指定角度 >= 就会将元素旋转到错误的方向180°
,忽略-
符号,不确定是什么原因,所以我rotateY
在我的示例中使用了 Firefox 正确处理的示例:
http://jsfiddle.net/V7Chp/
<div class="book">
<div class="box">
<div class="rotateaux"></div>
</div>
</div>
.book {
position: absolute;
z-index: -1;
top: 80px;
right: 300px;
-webkit-perspective: 300px;
-moz-perspective: 300px;
perspective: 300px;
-webkit-perspective-origin: 0% 50%;
-moz-perspective-origin: 0% 50%;
perspective-origin: 0% 50%;
}
.box {
position: relative;
width: 50px;
height: 90px;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform: rotateX(70deg);
-moz-transform: rotateX(70deg);
transform: rotateX(70deg);
}
.rotateaux {
position: relative;
background: green;
width: 50px;
height: 90px;
-webkit-transform-origin: 0% 50%;
-moz-transform-origin: 0% 50%;
transform-origin: 0% 50%;
}
.box:hover .rotateaux {
-webkit-animation: example 1.75s ease-in-out 0s infinite alternate;
-moz-animation: example 1.75s ease-in-out 0s infinite alternate;
animation: example 1.75s ease-in-out 0s infinite alternate;
}
@-webkit-keyframes example {
from {
-webkit-transform: rotateY(0deg);
}
to {
-webkit-transform: rotateY(-180deg);
}
}
@-moz-keyframes example {
from {
-moz-transform: rotateY(0deg);
transform: rotateY(-180deg);
}
to {
-moz-transform: rotateY(0deg);
transform: rotateY(-180deg);
}
}
@keyframes example {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(-180deg);
}
}