Find element that's on the middle of the visible screen (viewport), on scroll

前端 未结 3 2017
太阳男子
太阳男子 2021-01-02 10:48

I need to know if there is a way I can determine if a div is in the center of the screen.

HTML:

3条回答
  •  一向
    一向 (楼主)
    2021-01-02 11:41

    This is nice method: elementFromPoint()

    You can get the element in the center as so:

     var elem = document.elementFromPoint($(window).width()/2, $(window).height()/2);
    
    //if you want jquery element you can get it.
    var jqueryElem = $(elem);
    

提交回复
热议问题