我已经基于一个找到的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'
});
}
}
});
});
答案 0 :(得分:2)
jQuery的:
$(document).ready(function() {
$('#notifications a.active').next('div').siblings('div').hide();
$('#notifications a').click(function() {
$(this).addClass('active').siblings('a').removeClass('active');
var el = $(this).next('div');
check = (el.is(':visible')) ? el.slideUp() : function(){ $('#notifications div').slideUp(); el.slideDown(); }();
});
});