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 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>
添加回答
舉報