How to check if an element is off-screen

后端 未结 7 1812
太阳男子
太阳男子 2020-11-27 11:39

I need to check with jQuery if a DIV element is not falling off-screen. The elements are visible and displayed according CSS attributes, but they could be intentionally plac

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 11:59

    There's a jQuery plugin here which allows users to test whether an element falls within the visible viewport of the browser, taking the browsers scroll position into account.

    $('#element').visible();
    

    You can also check for partial visibility:

    $('#element').visible( true);
    

    One drawback is that it only works with vertical positioning / scrolling, although it should be easy enough to add horizontal positioning into the mix.

提交回复
热议问题