gpt4 book ai didi

javascript - 为移动设备禁用 jQuery 下拉菜单

转载 作者:行者123 更新时间:2023-11-28 05:23:19 27 4
gpt4 key购买 nike

我的网站有我用 CSS 制作的导航下拉菜单,但我最近将其更改为 jQuery,因此它是动画的。当它是 CSS 时,我能够在移动设备的最小断点上禁用下拉菜单。但是对于 jQuery,我不知道该怎么做。这是我的下拉代码。当视口(viewport)变得足够小时,我该怎么做才能使其禁用?

$(document).ready(function() {
$('.nav > li').mouseenter(function() {
$(this).children('.nav-content').slideDown(200);
});

$('.nav > li').mouseleave(function() {
$(this).children('.nav-content').slideUp(200);
});
});

这是现在的网站:

http://mattboy115.github.io/scarymonkeyshow/index.html

最佳答案

您可以使用 $(window).width()$(window).height() 检查屏幕的大小

有点像

$(document).ready(function() {
if($(window).width() > 800){
$('.nav > li').mouseenter(function() {
$(this).children('.nav-content').slideDown(200);
});

$('.nav > li').mouseleave(function() {
$(this).children('.nav-content').slideUp(200);
});
}
});

关于javascript - 为移动设备禁用 jQuery 下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35690878/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com