1 回答
TA贡献1811条经验 获得超4个赞
我认为你的问题是backface-visibility
将其设置为隐藏应该可以解决问题。
你想要一张翻转卡,对吗?然后创建 3D 透视并使背面不可见。
演示(点击翻转按钮翻转卡片):
$("#flip").click(function(){$(".pokemon").toggleClass("flipped")});
.card{
width: 400px;
height: 170px;
perspective: 600px;
}
.pokemon {
transform-origin: center right;
width: 100%;
height: 100%;
position: relative;
transition: transform 1s;
transform-style: preserve-3d;
}
.pokemon .front{
position: absolute;
height: 100%;
width: 100%;
backface-visibility: hidden;
transform: rotateY(0deg);
}
.pokemon .flipped{
position: absolute;
height: 100%;
width: 100%;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.pokemon .img-container img {
margin-top: 20px;
max-width: 90%;
}
.pokemon .info {
margin-top: 20px;
}
.pokemon .number {
background-color: rgba(0, 0, 0, 0.1);
border-radius: 10px;
font-size: 0.8em;
padding: 5px 10px;
font-family: 'Josefin Sans', sans-serif;
}
.pokemon .name {
margin: 15px 0 7px;
letter-spacing: 1px;
font-family: 'Cabin', sans-serif;
}
.pokemon .type {
background-color: rgba(0, 0, 0, 0.1);
border-radius: 10px;
font-size: 0.8em;
padding: 5px 10px;
font-family: 'Josefin Sans', sans-serif;
}
.pokemon.flipped {
transform: translateX(-100%) rotateY(-180deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card">
<div class="pokemon">
<div class="front">
<div class="img-container">
<img src="https://pokeres.bastionbot.org/images/pokemon/${pokemon.id}.png" />
</div>
<div class="info">
<span class="number">#${pokemon.id.toString().padStart(3, '0')}</span>
<a href="https://bulbapedia.bulbagarden.net/wiki/${name}_(Pok%C3%A9mon)" class="name">
<h3>${name}</h3>
</a>
<small class="type"><span>${type.charAt(0).toUpperCase() + type.slice(1)}</span></small>
</div>
</div>
<div class="flipped">
<div class="img-container">
<img src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png" />
</div>
<div class="info">
<span class="number">#${pokemon.id.toString().padStart(3, '0')}</span>
<h3 class="name">${name}</h3>
<small class="type"><span>${ability}</span></small>
</div>
</div>
</div>
</div>
<button id="flip">
flip!
</button>
添加回答
举报