这里只提供了jquery封装的代码段,至于HTML中的结构和元素样式不在此列出,本代码段只起到一个手风琴特效封装原理的参考作用。
;(function ($) {
$.fn.extend({
'accordition': function (colors, width) {
colors = colors || [];
width = width || 0;
var $li = this.find('li');
var $boxLength = this.width();
var $maxLength = $boxLength - ($li.length - 1) * width;
var $aveLength = $boxLength / $li.length;
$li.each(function (i, e) {
$(e).css('backgroundColor', colors[i]);
});
$li.on('mouseenter', function () {
$(this).stop().animate({width: $maxLength}).siblings().stop().animate({width: width});
});
$li.on('mouseleave', function () {
$li.stop().animate({width: $aveLength});
});
}
})
})(jQuery);