简体   繁体   English

jQuery问题选择CSS3翻转动画的特定元素?

[英]jQuery issue selecting a specific element for a CSS3 flip animation?

I have a modified css3 flip div demo which I am having problems with. 我有一个修改过的css3 flip div demo我遇到了问题。 I can make the div flip no problem and display the other side but my back side doc which has a cross to 'close' the div (basically remove the class) never works. 我可以让div翻转没有问题并显示另一边但我的背面文档有一个交叉'关闭'div(基本上删除类)永远不会工作。 Can someone see what I am doing wrong or point me in the right direction 有人可以看到我做错了什么或指出我正确的方向

$('.close-face').on('click', function(){
    var card = $(this).closest('flip');
    alert(card.html());
    card.removeClass('flipped');
});

http://jsfiddle.net/GDdtS/10424/ http://jsfiddle.net/GDdtS/10424/

Thank you. 谢谢。

It's because when you click on the .flip element, the class is added back again. 这是因为当您单击.flip元素时,该类将再次添加回来。 Only add the class flipped when clicking on the front of the card in order to prevent it from being added when clicking the back. 只有在单击卡片正面时才会添加flipped的类,以防止在单击背面时添加该类。

In addition, you were trying to remove the class .flipped from the .flip element, meanwhile the class is on the .card element. 此外,您试图从.flip元素中删除.flipped类,同时该类位于.card元素上。 Just target the .flipped element instead. 只需定位.flipped元素即可。

Updated Example 更新的示例

$('.flip .front').on('click', function() {
  $(this).closest('.card').addClass('flipped');
});


$('.close-face').on('click', function() {
  $(this).closest('.flipped').removeClass('flipped');
});

It should be $(this).closest('.flip') . 它应该是$(this).closest('.flip') You missed the dot. 你错过了这个点。

You should also remove the class from $(this).closest('.card') 您还应该从$(this).closest('.card')删除该类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM