开发者

If offset.top listen

开发者 https://www.devze.com 2023-02-25 04:26 出处:网络
I have a long scrolling page, and want to test if an element is 100px from the top, then apply a class elsewhere (until the next element in line is 100px from the top)

I have a long scrolling page, and want to test if an element is 100px from the top, then apply a class elsewhere (until the next element in line is 100px from the top)

If I could 开发者_JS百科just get the basic statement I would be ecstatic, anything extra would be a bonus!


$('#id').scroll(function() {
    if(this.offset.top <= 100) {
        //Do something
    }
});

This should do what you want. It adds a binding for the scroll event to the element with an id of 'id'. Whenever you scroll the page, it will then call the function and check the offset, then do what you want if needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消