Javascript 计算滚动时窗口的高度
我创建了一个代码,用于在滚动时计算高度Javascript 计算滚动时窗口的高度,javascript,jquery,html,Javascript,Jquery,Html,我创建了一个代码,用于在滚动时计算高度 当窗口高度大于我的第一个分区高度时, 第二部分将显示 当我从底部回到顶部时,第二部分将隐藏 代码: $(window).scroll(function() { var $height = $(window).scrollTop(); var outerheigth = $(".smart-light-top-bnr").height(); var sliderheigth = $(".smart-light-edu1").heig
$(window).scroll(function() {
var $height = $(window).scrollTop();
var outerheigth = $(".smart-light-top-bnr").height();
var sliderheigth = $(".smart-light-edu1").height();
var outheigth = parseInt(outerheigth)+parseInt(sliderheigth);
if($height >= outerheigth && $height <= outheigth) {
document.getElementById("smart-light-edu").style.display = "block";
} else {
document.getElementById("smart-light-edu").style.display = "none";
}});
$(窗口)。滚动(函数(){
var$height=$(window.scrollTop();
var outerheigth=$(“.smart light top bnr”).height();
var sliderheigth=$(“.smart-light-edu1”).height();
var outheigth=parseInt(outerheigth)+parseInt(sliderheigth);
如果($height>=outerheighth&&$heightAhhh!。在搜索并遇到一些错误后,我最终得到了解决方案。。
代码如下:
$(window).scroll(function() {
var $height = $(window).scrollTop();
var outerheigth = $(".smart-light-top-bnr").height();
var sliderheigth = $(".smart-light-edu1").height();
var outheigth = parseInt(outerheigth)+parseInt(sliderheigth);
if($height >= outerheigth && $height <= outheigth) {
swiper.init();
}
});
$(窗口)。滚动(函数(){
var$height=$(window.scrollTop();
var outerheigth=$(“.smart light top bnr”).height();
var sliderheigth=$(“.smart-light-edu1”).height();
var outheigth=parseInt(outerheigth)+parseInt(sliderheigth);
如果($height>=outerheigth&&$height,您可以用检查一下吗如果($height=outerheigth&&$height,如果您使用的是jQuery,那么为什么不使用$(“#智能灯光教育”).hide()
感谢Dhaval Purohit,用户从第一个部分穿过,然后第二个部分显示,在第三个部分到达,第二个部分再次需要隐藏。您首先需要所有的部分高度,根据这一点,您需要设定条件,如果主高度位于这些部分之间,则该部分不应显示。