【发布时间】:2018-11-27 11:15:17
【问题描述】:
我正在玩this card game,我想添加一个卡片翻转动画。
我已经在谷歌上搜索了答案,但大多数解决方案都参考 jquery(我不想只为 1 个动画实现)或 CSS3 (I liked this example)。运气不好。
js游戏使用如下(来自cardgamecore.js):
playingCard.redrawCardImage()强制重绘一张牌
playingCard.showFace(bool: face) 将卡片设置为面朝上或面朝下,并在需要时重新绘制。 true = 面朝上,false = 面朝下。
playingCard.prototype.redrawCardImage = function () {
// Set or change the image showing on the card face
if( !this.faceImage || !this.cardSet.backImage ) { return; }
// Bug in Firefox - alt attributes do not change unless they are made _before_ an SRC change
this.cardImage.setAttribute('alt',this.wayup?(this.cardSet.cardNames[this.number-1]+' '+this.suit):this.cardSet.cardWord);
this.cardImage.src = this.wayup ? this.faceImage : this.cardSet.backImage;
};
playingCard.prototype.showFace = function (oWhich) {
// Used to flip a card over
if( this.redrawNewImage != oWhich ) {
this.wayup = oWhich;
this.redrawCardImage();
}
};
因此,当卡片显示其背面时,则为 playingCard.showFace = false。当您单击它时,playingCard.showFace = true 并重新绘制图像。此时卡片应该有一个漂亮的翻转动画。
但是怎么做呢?
【问题讨论】:
-
您喜欢的 CSS3 示例遇到了哪些问题?
-
嗯,它更像是在哪里添加代码以使其工作。像
addClass X(X 有 css3 翻转动画)这样的东西就足够了吗?如果就这么简单,我应该把它放在showFace或redrawCardImagefunction 中吗? -
加个类就这么简单,我觉得在showFace里会更好。我不确定是否不再需要 redrawCardImage,因为您可以在 css 中同时拥有正面和背面图像,而不显示卡片的背面。
标签: javascript css animation css-animations