当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Change CSS class after scrolling 100% screen height down

问题描述:

I'm making a single page website and i want to show nav-menu on second part till end. I found this question:

Change CSS class after scrolling 1000px down

...and i used the answer of AlienWebguy

$(document).scroll(function() {

$('#menu').toggle($(this).scrollTop()>1000)

});​

But i don't want to do 1000px. I want to use it 100% of screen that it can change with different platforms or resolution.

Do you know what can i do?

网友答案:

Use this:

$(document).scroll(function() {
    var windowHeight = $(window).height();
    $('#menu').toggle($(this).scrollTop()>windowHeight)

});
网友答案:

You can replace 1000 with $(window).height()

As in:

$(document).scroll(function() {
    $('#menu').toggle($(this).scrollTop()>$(window).height())
});
网友答案:

You can use that :

$(document).on("scroll", function(){
    if($(document).scrollTop() >= ($(document).height() - $(window).height())){
        //here, you're at the bottom of the page
        console.log("BOTTOM");
    } else {
        //here, you're not arrived yet
    }
});

it will work for every screen size, in theory.

分享给朋友:
您可能感兴趣的文章:
随机阅读: