gpt4 book ai didi

javascript - 我想做一个内存游戏。创建卡片的最佳方式是什么

转载 作者:行者123 更新时间:2023-11-28 16:43:42 24 4
gpt4 key购买 nike

所以基本上我想用 JS、HTML 和 CSS 制作一个内存游戏。我希望能够单击卡片,然后卡片应该以翻转动画翻转。我不想创建 20 个按钮。有没有更好的方法来创建带有 CSS 动画的卡片?我有点知道如何创建动画。

  .flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
/* Remove this if you don't want the 3D effect */
}


/* This container is needed to position the front and back side */

.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}


/* Do an horizontal flip when you move the mouse over the flip box container */

.flip-card:click .flip-card-inner {
transform: rotateY(180deg);
}


/* Position the front and back side */

.flip-card-front,
.flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
/* Safari */
backface-visibility: hidden;
}


/* Style the front side (fallback if image is missing) */

.flip-card-front {
background-color: #bbb;
color: black;
}


/* Style the back side */

.flip-card-back {
transform: rotateY(180deg);
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="frontpageofCard" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="flip-card-back">
<img src="Backpage" alt="Avatar" style="width:300px;height:300px;">
</div>
</div>
</div>

我想用JS在后台分配随机图片。

最佳答案

你可以像这样用 JS 创建卡片:

var card = "<div class='flip-card'><div class='flip-card-inner'><div class='flip-card-front'><img src='frontpageofCard' alt='Avatar' style='width:300px;height:300px;'></div><div class='flip-card-back'><img src='Backpage' alt='Avatar' style='width:300px;height:300px;'></div></div></div>"

for (let i = 0; i < 20; i++) {
document.querySelector("#container").innerHTML += card
}
 .flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
/* Remove this if you don't want the 3D effect */
}


/* This container is needed to position the front and back side */

.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}


/* Do an horizontal flip when you move the mouse over the flip box container */

.flip-card:click .flip-card-inner {
transform: rotateY(180deg);
}


/* Position the front and back side */

.flip-card-front,
.flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
/* Safari */
backface-visibility: hidden;
}


/* Style the front side (fallback if image is missing) */

.flip-card-front {
background-color: #bbb;
color: black;
}


/* Style the back side */

.flip-card-back {
transform: rotateY(180deg);
<div id="container">
</div>

关于javascript - 我想做一个内存游戏。创建卡片的最佳方式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60831563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com