gpt4 book ai didi

javascript - 如果 screen.height 低于 460px,则删除一个类

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:00 25 4
gpt4 key购买 nike

我有一个固定导航的元素,但导航比 460 像素以下的屏幕长,所以我想删除固定导航,当 screen.height 低于 460 像素时。这是我的代码,我尝试了 3 种不同的方法,但都不起作用:

// var ratio = window.devicePixelRatio || 1;
//var ScreenHeight = screen.height * ratio;
// var ScreenHeight = widows.screen.height;
var ScreenHeight = window.screen.availHeight;

if (ScreenHeight < 460) {
$('.nav-container').removeClass('sticky');
}

var headerHeight = $('header').height();
var main = 120;
main = document.getElementById("main").offsetHeight;
$(window).scroll(function () {

if (main > 825) {
var headerHeight = $('header').height();
if ($(window).scrollTop() >= headerHeight) {
$('.nav-container').addClass('sticky');
} else {
$('.nav-container').removeClass('sticky');
}
}
});

我做错了什么?

最佳答案

你试过 $(window).height(); 而不是 window.screen.availHeight 吗?

关于javascript - 如果 screen.height 低于 460px,则删除一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909609/

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