[英]Jquery menu not working on click
I can get get my menu working on hover, but it doesnt work when I use mousedown: 我可以使菜单在悬停上工作,但是当我使用mousedown时它不起作用:
http://codepen.io/anon/pen/Krflq http://codepen.io/anon/pen/Krflq
$(document).ready(function () {
$('#nav li').mousedown(
function () {
$('ul', this).stop().slideDown(100);
},
function () {
//hide its submenu
$('ul', this).stop().slideUp(100);
}
);
});
Can anyone show me where I have gone wrong please? 谁能告诉我我哪里出问题了? I want the menu to open up when I click the top-level and stay open.
我希望在单击顶层并保持打开状态时打开菜单。
You can't have two functions in mousedown event so use them separately. mousedown事件中不能有两个功能,因此请分别使用。
mousedown
and mouseleave
. mousedown
和mouseleave
。
Check this : 检查一下:
$(document).ready(function () {
$('#nav li').mousedown(
function () {
$('ul', this).stop().slideDown(100);
}
).mouseleave(
function () {
$('ul', this).stop().slideUp(100);
}
);
});
I would use click()
and slideToggle()
. 我会使用
click()
和slideToggle()
。 Try this: 尝试这个:
$(document).ready(function () {
$( "#nav li" ).click(function() {
$('ul', this).stop().slideToggle(100);
});
});
Also you have to declare your desirable functionallity. 另外,您还必须声明所需的功能。 All we do is quess now
我们现在要做的就是提问
Use Toggle
event 使用
Toggle
事件
$(document).ready(function () {
$('#nav li').mousedown(function(){
$('ul #items').toggle(1000);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.