最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery selector by position on page available? - Stack Overflow

programmeradmin4浏览0评论

Is there a selector available in jQuery to select elements which have a specific position of the page, for example all elements that have an offsetTop bigger than, say, 100px?

I tried:

$('span[offsetTop>100]')

because just as we can check if an attribute equals to some value, I thought it might be possible to check if an attribute is larger than some value. This, however, does not work. Is this possible at all?

Is there a selector available in jQuery to select elements which have a specific position of the page, for example all elements that have an offsetTop bigger than, say, 100px?

I tried:

$('span[offsetTop>100]')

because just as we can check if an attribute equals to some value, I thought it might be possible to check if an attribute is larger than some value. This, however, does not work. Is this possible at all?

Share Improve this question edited Feb 27, 2012 at 13:14 pimvdb asked Feb 8, 2011 at 18:22 pimvdbpimvdb 155k80 gold badges311 silver badges356 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You'd need to use the filter()(docs) method to filter <span> elements by their offset:

$('span').filter(function() {
    return $(this).offset().top > 100;
});
发布评论

评论列表(0)

  1. 暂无评论