我根据一个找到的 jquery ui 创建了简单的手风琴菜单。我在为元素设置动画时遇到问题,单击时我无法正确使用向上或向下滑动动画,并且如果使用它,还会出现许多其他问题。因此,任何帮助都将有助于获得动画。
JS 小提琴:http: //jsfiddle.net/cZbr6/
脚本
$(document).ready(function() {
var notfContainer = $('#notifications');
notfContainer.find("a").each(function() {
var e = $(this);
if(!e.hasClass('active')) {
e.next().css({
'display':'none'
}); //hide all other div's and set height as 0px
}
});
notfContainer.on('click' , function(event) {
var target = $(event.target); //Used to find the element on which the click event has happened.
if(target.is("a")) { //If the click event occurred on <a>
var self = $(target); //Select the element
if(self.hasClass('active')) { //If is is already expanded .. has active class
return; //just .. return
}else {
notfContainer.find("a").each(function() {
var e = $(this);
if(e.hasClass('active')) {
e.removeClass('active');
e.next().css('display','none'); //hide all other div's
return false; //break the loop
}
});
self.addClass('active');
self.next().css({
'display':'block',
'height':'160px'
});
}
}
});
});