How can you use jQuery measure how far down the user has scrolled?

前端 未结 2 1668
再見小時候
再見小時候 2020-12-18 02:01

I need to change the style of an element after the user has scrolled down beyond a certain number of pixels, and then change it back once the user has scrolled back up. I\'m

2条回答
  •  青春惊慌失措
    2020-12-18 02:26

    See scrollTop, scrollLeft and Events/Scroll.

    Example:

    $('div#something').scroll(function () {
        if ($(this).scrollTop() > 200) {
            $(this).addClass('foo');
        } else {
            $(this).removeClass('foo');
        }
    });
    

提交回复
热议问题