gpt4 book ai didi

javascript - 如何仅将 jquery 函数应用于大屏幕

转载 作者:行者123 更新时间:2023-11-30 09:49:29 25 4
gpt4 key购买 nike

我有这段代码,它工作得很好,但我只想将它应用于大屏幕而不是移动设备。任何帮助将不胜感激。

<script>

(function($) {
jQuery(function($) {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function() {
location.href = this.href;
});
});
})(jQuery);

</script>

最佳答案

试试这个:

if ( $(window).width() > 739) {     
//Add your code for large screen
}
else {
//Add code for small screen
}

编辑:将其应用于您的代码(使用@soloughlin3 建议的调整大小)

$(document).ready(myfunction);
$(window).on('resize',myfunction);

function myfunction() {
if ( $(window).width() > 739) {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function() {
location.href = this.href;
});
}
}

关于javascript - 如何仅将 jquery 函数应用于大屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37213049/

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