滑鼠懸停主選單項目,子選單以 3D 翻轉動畫(rotateY(90deg)→0deg)配合水平位移展開,極具立體感。
nav {
width: 650px; margin: 100px auto; background: #455552; position: relative;
}
.nav-ul { list-style: none; }
.nav-ul > li { display: inline-block; position: relative; }
.nav-ul a { display: inline-block; padding: 10px 20px; color: #fff; text-decoration: none; }
.nav-ul a:hover { background: #1ABC9C; }
/* 子選單 3D 動畫 */
.nav-ul a + ul {
position: absolute; list-style: none;
transition: opacity 0.5s;
-webkit-perspective: 800; -webkit-transform-style: preserve-3d;
}
.nav-ul a + ul li {
position: relative; left: -40px; opacity: 0; width: 150px;
transition: transform 1.5s, opacity 0.8s;
}
.nav-ul a:hover + ul li,
.nav-ul a + ul:hover li {
opacity: 1;
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
.nav-ul a + ul li:nth-child(1) { -webkit-transform: rotateY(90deg) translateX(10px); transform: rotateY(90deg) translateX(10px); }
.nav-ul a + ul li:nth-child(2) { -webkit-transform: rotateY(120deg) translateX(20px); transform: rotateY(120deg) translateX(20px); }
.nav-ul a + ul li:nth-child(3) { -webkit-transform: rotateY(150deg) translateX(30px); transform: rotateY(150deg) translateX(30px); }
.nav-ul a + ul li:nth-child(4) { -webkit-transform: rotateY(180deg) translateX(40px); transform: rotateY(180deg) translateX(40px); }
perspective: 800:建立 3D 空間景深,數值越小透視越強。transform-style: preserve-3d:讓子元素保持在 3D 空間中(預設 flat 會攤平)。rotateY(90deg→0deg):繞 Y 軸旋轉,配合 translateX 產生「翻開」視覺。transition 分別控制 transform(旋轉位移)與 opacity(淡入)時程,產生層次感。touchstart/click 切換 .open 類別觸發動畫。preserve-3d。