我有一副卡片與甲板上的背景圖像,點擊時他們做一個翻轉動畫,然後將背景圖像更改爲前景圖像,面臨的等同。帶有兩個背景圖像的CSS變換Div
這些卡中的每一個都是一個div。
我的問題是,當卡被點擊後轉身時,前面的背景圖像也被顛倒過來。任何想法如何我可以解決這個問題?
這裏是小提琴:https://jsfiddle.net/667nxfze/
這是我的一個卡的HTML:
<div id='pack_cont' data-deckimage="url('/image/decks/deck1.png')">
<div class='card init' data-image="url('/image/card/card1.png')"></div>
</div>
這裏是JavaScript能夠反應是:
var card = $(this);
card.toggleClass('open');
setTimeout(function(){
card.toggleClass('opened');
},300);
if(card.hasClass('open')){
//Show that card image
card.css('background-image', card.data('image'));
}else{
//Show the Deck Image
card.css('background-image', card.parent().data('deckimage'));
}
這裏是CSS類:
.card{
width: 147px;
height: 280px;
border-radius: 18px;
position: absolute;
background-size: contain;
background-repeat: no-repeat;
cursor: pointer;
text-align: center;
/*all transition to take 1s */
transition:all 1s;
-ms-transition:all 1s;
-webkit-transition:all 1s;
-moz-transition:all 1s;
/*make card non selectable*/
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/*while opening a card, again shift transform origin
to vertical and horizontal center axis
to give an actual flip effect
*/
.card.open{
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.card.opened{
background-image: none;
}
,但圖像仍然出現點擊之後逆轉.. –
剛剛更新我的答案:CSS變換屬性「規模」是你想要的 –
呀,它解決了scale屬性我問題。謝謝! –