Javascript 不是jQuery链中下一个元素上的选择器
我有一系列方法可以在Javascript 不是jQuery链中下一个元素上的选择器,javascript,jquery,html,chain,Javascript,Jquery,Html,Chain,我有一系列方法可以在li中找到ul,并设置其高度的动画 $('.collapse-trigger').click(function() { if($(this).next('.collapse-ul').height() == 0) { $(this).css('background', '#000000'); var height = $(this).next('.collapse-ul').children().length; $(
li
中找到ul
,并设置其高度的动画
$('.collapse-trigger').click(function() {
if($(this).next('.collapse-ul').height() == 0) {
$(this).css('background', '#000000');
var height = $(this).next('.collapse-ul').children().length;
$(this).next('.collapse-ul').animate({height: height*42}, 500); // multiply height with number of menupoints
}
else {
$(this).css('background', '#414141');
$(this).next('.collapse-ul').animate({height: 0}, 500);
}
});
有了这个,我可以折叠每个ul
,然后再次单击,它就会回到0
。我打算做的是,当一个ul
正在进行动画制作时,其他的动画制作回到零
我想我需要像这样的东西。不是(这个)
,而是与之斗争。
我的尝试:
$('this').next().not('.collapse-ul', this).animate({height: 0}, 500); // <-- inside the not method I don't know how to write it
$('this').next().not('.collapse ul',this.).animate({height:0},500);// 试试这个:您可以先找到可折叠的ul,然后使用.not()
你能发布你的HTML吗。。??或者一个演示会很棒…谢谢,它很接近,唯一的一点是,它将所有其他动画设置为零,然后扩展所有动画。我是否遗漏了一个阻塞变量?编辑:无需担心,它正在工作……)
$('.collapse-trigger').click(function() {
if($(this).next('.collapse-ul').height() == 0) {
$(this).css('background', '#000000');
var height = $(this).next('.collapse-ul').children().length;
var $collapseUl = $(this).next('.collapse-ul');
//filter current collapsible ul
$('.collapse-ul').not($collapseUl).animate({height: 0}, 500);
$collapseUl.animate({height: height*42}, 500); // multiply height with number of menupoints
}
else {
$(this).css('background', '#414141');
$(this).next('.collapse-ul').animate({height: 0}, 500);
}
});