How to check if an element is off-screen

后端 未结 7 1819
太阳男子
太阳男子 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 12:09

    You could check the position of the div using $(div).position() and check if the left and top margin properties are less than 0 :

    if($(div).position().left < 0 && $(div).position().top < 0){
        alert("off screen");
    }
    

提交回复
热议问题