效果預覽:https:///keleyi/phtml/jqmenu/index.htm
這個菜單的視覺關鍵是「傾斜的色塊」:每個 li 裡塞一個 p 當底色、一個 b 當左側的小尖角,兩者都用絕對定位藏在 li 左側(left:-164px)。滑鼠移入時把 p 動畫推到 left:0,看起來就像色塊從左邊斜插入位;移出再退回。再用第二個 ready 區塊依序累加 margin-left,讓整排項目呈現輕微的階梯錯位。
.keleyimenu{width:355px;background:url(https:///keleyi/phtml/jqmenu/index/nav-bg.png) no-repeat;}
.keleyimenu ul{margin:0 0 0 42px;}
.keleyimenu ul li{width:164px;height:29px;padding-bottom:8px;overflow:hidden;position:relative;float:left;display:inline;}
.keleyimenu ul li a{display:block;width:164px;height:29px;line-height:26px;font-size:16px;color:#FFFFFF;text-indent:62px;position:relative;z-index:100000;}
.keleyimenu ul li p{position:absolute;z-index:100;top:0;left:-164px;width:164px;height:29px;background:url(https:///keleyi/phtml/jqmenu/index/nav-libg.png) no-repeat;}
.keleyimenu ul li b{position:absolute;z-index:100000;top:0;left:0;display:block;width:11px;height:29px;background:url(https:///keleyi/phtml/jqmenu/index/nav-jiao2.png) no-repeat;}
.keleyimenu ul li.current p{left:0;}
.keleyimenu ul li.current a{color:#0072d2;}
$(function () {
$(".ke"+"leyimenu ul li").append("<b class='pngFix'></b><p class='pngFix'></p>");
$(".keleyimenu ul li").hover(function () {
if ($(this).attr("class") != "current") {
$(this).children("p").stop().animate({ left: "0px" }, 200);
$(this).children("a").css({ color: "#0072d2" }, 900);
}
}, function () {
if ($(this).attr("class") != "current") {
$(this).children("p").stop().animate({ left: "-164px" }, 300);
$(this).children("a").css({ color: "#FFFFFF" }, 900);
}
});
$(".kele"+"yimenu ul li.current").unbind("hover");
});
$(function ($) {
var left = 0;
var length = $(".keleyimenu li").length;
for (length; length > 0; length--) {
left += 12.60;
$(".keleyimenu li").eq(length - 1).css("margin-left", left)
}
});
function setNav(id) {
var navList = $(".keleyimenu ul li");
$(navList).eq(id - 1).addClass("current");
}
程式碼中用到的 eq 函數詳解:https:///a/bjac/tmx4mq76.htm
菜單大全:https:///a/bjac/veugsmw9.htm