封装手风琴!使用jQuery!

时间:2023-03-09 03:55:25
封装手风琴!使用jQuery!
 //封装手风琴
/**
*
*
*
*/ $.fn.accordion = function (colors, width) { var width=width||0;
var colors= colors||[]; $li = this.find("li");
var boxWidth = this.width();
var avgWidth = boxWidth / $li.length;
var maxWidth = boxWidth - ($li.length - 1) * width; //更改li的颜色
$li.each(function (i, e) {
$(e).css("backgroundColor", colors[i]);
}); //鼠标进入事件
$li.on("mouseenter", function () {
$(this).stop().animate({
"width": maxWidth
}).siblings().stop().animate({
"width": width
});
})
//鼠标离开事件
$li.on("mouseleave", function () {
$li.stop().animate({
"width": avgWidth
});
})
return this;
}

先提供代码!有时间会更新详细的内容~~~~~~~~~~~