Về cơ bản những gì tôi đang cố gắng làm là cho phần tử hoạt ảnh CSS khi nó đạt được một lớp, sau đó đảo ngược hoạt ảnh đó khi tôi xóa lớp mà không phát hoạt ảnh khi DOM hiển thị.Có thể đảo ngược hoạt ảnh css khi xóa lớp học?
Fiddle ở đây: http://jsfiddle.net/bmh5g/
Như bạn có thể nhìn thấy trong fiddle, khi bạn di chuột vào nút "Di Me", #item
flips xuống. Khi bạn di chuột qua nút di chuột, #item
sẽ biến mất. Tôi muốn #item
để lật ngược (lý tưởng là sử dụng cùng một hình động nhưng ngược lại). Điều này có thể không?
HTML:
<div id='trigger'>Hover Me</div>
<div id='item'></div>
CSS:
#item
{
position: relative;
height: 100px;
width: 100px;
background: red;
-webkit-transform: perspective(350px) rotateX(-90deg);
transform: perspective(350px) rotateX(-90deg);
-webkit-transform-origin: 50% 0%;
transform-origin: 50% 0%;
}
#item.flipped
{
animation: flipper 0.7s;
animation-fill-mode: forwards;
-webkit-animation: flipper 0.7s;
-webkit-animation-fill-mode: forwards;
}
@keyframes flipper
{
0% { transform: perspective(350px) rotateX(-90deg); }
33% { transform: perspective(350px) rotateX(0deg); }
66% { transform: perspective(350px) rotateX(10deg); }
100% { transform: perspective(350px) rotateX(0deg); }
}
@-webkit-keyframes flipper
{
0% { -webkit-transform: perspective(350px) rotateX(-90deg); }
33% { -webkit-transform: perspective(350px) rotateX(0deg); }
66% { -webkit-transform: perspective(350px) rotateX(10deg); }
100% { -webkit-transform: perspective(350px) rotateX(0deg); }
}
Javascript:
$('#trigger').on({
mouseenter: function(){
$('#item').addClass('flipped');
},
mouseleave: function(){
$('#item').removeClass('flipped');
}
})
Câu trả lời hay nhất cho đến nay - tôi không nghĩ rằng nó có thể làm những gì tôi muốn. – Jake