fadeIn在悬停时工作,但在单击/单击时不工作
fadeIn working on hover but not onClick/click
显示子列表项会在hover()
上淡入,但不会在click()
或onclick()
上淡入。http://jsfiddle.net/gymbry/mgMK4/
最简单的解决方案:
$('ul li').click(function (e) { // jQuery click event. The "e" is the "event" argument
e.stopPropagation(); // prevents a parent elements "click" event from fireing (useul here since this asigns to inner li's as well)
var ul = $(this).children('ul'); // find any children "ul" in this li
// check if ul exist and toggle (not completely neccesary as jquery will simply preform no action if element is not found)
if (ul.length) ul.fadeToggle('fast');
});
工作示例
$('ul li').click(function (e) { // jQuery click event. The "e" is the "event" argument
e.stopPropagation(); // prevents a parent elements "click" event from fireing (useul here since this asigns to inner li's as well)
var ul = $(this).children('ul'); // find any children "ul" in this li
if (ul.length) { // check if ul exist
if (ul.is(':visible')) { // check ul is visible
ul.fadeOut('fast');
}
else {
ul.fadeIn('fast');
}
}
});
示例2
请记住,上述解决方案不处理关闭时打开的同级菜单或更深层次的菜单。要获得更完整的解决方案,请尝试以下操作:
$('ul li').click(function (e) {
e.stopPropagation();
var ul = $(this).children('ul');
$(this).siblings().each(function(i) {
var ul = $(this).children('ul');
if (ul.length) if (ul.is(':visible')) {
ul.find('ul').fadeOut('fast');
ul.fadeOut('fast');
}
});
if (ul.length) {
if (ul.is(':visible')) {
ul.find('ul').fadeOut('fast');
ul.fadeOut('fast');
}
else ul.fadeIn('fast');
}
});
示例3
相关文章:
- JavaScript-在手机上不工作的情况下,在外部单击时隐藏元素
- addEventListener的Javascript代码不工作!?(单击时打开放大的img)
- button.单击两次删除附加操作后不工作
- 我该如何阻止单击方法多次工作
- Hammer.js滑动不会'单击按钮后才能工作
- 为什么不'加载$(document.ready(function)后,单击“工作”
- jQuery animate只在单击时工作一次
- 单击'Backbone.js视图'不要工作
- 谷歌工作表中的按钮,当单击时,会更改特定单元格的背景
- 单击水平滚动库中的图像以居中显示无法工作的功能
- 禁用触摸设备上的单击链接未按预期工作
- Chrome扩展程序:浏览器操作单击按钮工作一次
- 单击仅工作一次
- 单击事件在 iPad 中使用 Angularjs 无法正常工作
- 我需要在单击时运行两个函数.即使嵌套在一起,我也无法让它们都工作
- 打开选择之前的事件.(单击工作速度不够快)
- 需要单击以完全执行,然后才能再次单击工作
- 在具有多个链接的ng网格中创建自定义单元格内容-使ng单击工作
- jQuery单击工作一次,而不是两次
- ng-单击“工作不正常”