Scroll if element is not visible

前端 未结 9 733
旧时难觅i
旧时难觅i 2020-12-14 17:57

how to determine, using jquery, if the element is visible on the current page view. I\'d like to add a comment functionality, which works like in facebook, where you only sc

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 18:07

    There is a jQuery plugin which allows us to quickly check if a whole element (or also only part of it) is within the browsers visual viewport regardless of the window scroll position. You need to download it from its GitHub repository:

    Suppose to have the following HTML and you want to alert when footer is visible:

    So, add the plugin before the close of body tag:

    
    
    

    After that you can use it in a simple way like this:

    
    

    Here a demo

提交回复
热议问题