[英]how to change mega menu hover to on click in small screen size?
如何将巨型菜单悬停更改为单击?
$(function() { $(".dropdown").hover( function() { $('.dropdown-menu', this).stop(true, true).fadeIn("slow"); $(this).toggleClass('open'); }, function() { $('.dropdown-menu', this).stop(true, true).fadeOut("slow"); $(this).toggleClass('open'); }); });
我将.hover更改为.click,但是它不起作用。
您需要复制悬停方法。 没有DOM也很难确定,但是类似的东西应该可以工作。
$(function() {
$(".dropdown").click(function() {
if($(this).hasClass('open')) {
$('.dropdown-menu', this).stop(true, true).fadeOut("slow");
$(this).toggleClass('open');
} else {
$('.dropdown-menu', this).stop(true, true).fadeIn("slow");
$(this).toggleClass('open');
}
});
});
基本上,您需要检查菜单是否打开,并运行通常在悬停时会触发的代码。
希望这可以帮助。
当单击下拉菜单时,如果当前项处于隐藏状态,那么我将使用fadeIn
显示或打开元素。 否则,如果它已被打开或未被隐藏,则使用fadeOut
关闭它。
同样在第二段代码中,我确保当您单击菜单组件外部的任何位置时,菜单都将关闭。
$(function() {
$(".dropdown").click(function() {
if($(this).find(".dropdown-menu").is(":hidden")){
//opening menu when it is not open already
$(".dropdown-menu").hide();
$('.dropdown-menu', this).stop(true, true).fadeIn("slow");
}
else{
//closing menu when it is open already on same item click
$('.dropdown-menu', this).stop(true, true).fadeOut("slow");
}
});
});
$('html').click(function() {
//Hide the menus if visible when click outside menu
$('.dropdown-menu', this).stop(true, true).fadeOut("slow");
});
$('.dropdown, .dropdown-menu').click(function(event){
event.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.