不是jQuery链中下一个元素上的这个选择器
Not this selector on next element in jQuery chain
我有一系列jQuery方法来在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
动画化时,其他的动画化回零。
我想我需要.not(this)
这样的东西,但很难做到。我的尝试:
$('this').next().not('.collapse-ul', this).animate({height: 0}, 500); // <-- inside the not method I don't know how to write it
感谢
试试这个:你可以先找到可折叠的ul,然后用.not()
过滤它
$('.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);
}
});
相关文章:
- 在动态创建的元素上获取对特定选择器的引用
- 使用CSS或js,使用动态选择器选择任意li的下一个元素
- Webdriver.io pageObject模式-通过传递参数来定义元素选择器
- 如何通过选择器元素将图像添加到javascript下拉警报消息中
- Angular Datetimepicker:指令'的模板;uib时间选择器'必须只有一个根元素
- 选择不带选择器的元素,仅使用元素ID
- 动态修改一个元素,使其与给定的选择器匹配
- 循环遍历元素jquery选择器
- jquery点击选择器附加在多个元素上
- 如何检查日期选择器和时间选择器元素是否使用JQuery/Javascript设置
- jquery复杂选择器,按元素和类以开头
- 如何查找包含特定选择器的父元素
- 如何在AnglujarJS ng中继器中选择特定元素
- 我可以让 jQuery UI 日期选择器元素在单击日期时不重置吗?
- Jquery 选择器元素内部的其他
- 当选择器元素被另一个元素遮挡时使用jQuery.on()
- Jquery返回对象而不是选择器元素
- 没有类的jQuery选择器元素
- 重新加载tableview的选择器元素与更新的数据在钛
- 引导时间选择器只选择第一个时间选择器元素