導航項為 6 個方塊,懸停時鏈接元素上下縮放「翻牌」一次;點擊時放大淡出再縮小歸位,產生 3D 翻轉視覺錯覺。
var nummove = 0, numout = 0; // 防重入鎖
$(function() {
$("#btncell li").hover(
function() { // 進入:快速縮放動畫
if (nummove === 0) {
nummove = 1;
$("a", this)
.animate({ height: "0px", top: "25px" }, 80, function() { nummove = 0; })
.animate({ height: "28px", top: "10px" }, 80)
.css("background", "yellow");
}
},
function() { // 離開:反向動畫
if (numout === 0) {
numout = 1;
$("a", this)
.animate({ height: "0px", top: "25px" }, 80, function() { numout = 0; })
.animate({ height: "28px", top: "10px" }, 80)
.css("background", "#888");
}
}
);
$("#btncell li a").click(function() {
var $li = $(this).parent().css("z-index", 2);
$(this).animate({
height: "558px", top: "-255px", width: "1000px", left: "-460px",
opacity: 'toggle', lineHeight: '558px', fontSize: '500px'
}, 1000)
.animate({
height: "28px", top: "10px", width: "50px", left: "25px",
opacity: 'toggle', lineHeight: '28px', fontSize: '12px'
}, 400, function() {
$li.css("z-index", 1);
});
});
});
nummove/numout 防止快速進出觸發動畫疊加。height/width/top/left/opacity/lineHeight/fontSize,產生爆炸式放大效果。<ul id="btncell">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
...
</ul>
<style>
#btncell { width:300px; height:100px; border:1px solid #777; margin:50px auto; }
#btncell li { width:100px; float:left; height:50px; position:relative; z-index:1; }
#btncell li a {
display:block; width:50px; height:28px; border:2px solid #333;
background:#888; text-decoration:none; text-align:center; line-height:28px;
position:absolute; left:25px; top:10px; overflow:hidden;
}
</style>
.flip-card {
perspective: 1000px; width: 100px; height: 50px;
}
.flip-card-inner {
position: relative; width: 100%; height: 100%;
transition: transform 0.6s; transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner {
transform: rotateX(180deg);
}
.flip-card-front, .flip-card-back {
position: absolute; width: 100%; height: 100%;
backface-visibility: hidden; display: flex; align-items: center; justify-content: center;
}
.flip-card-back { transform: rotateX(180deg); background: yellow; }
純 CSS 實現真 3D 翻轉,無 JS 計算、GPU 加速、代碼量減 80%。