Finding the position of bottom of a div with jquery

前端 未结 8 662
粉色の甜心
粉色の甜心 2020-12-07 18:29

I have a div and want to find the bottom position. I can find the top position of the Div like this, but how do I find the bottom position?

var top = $(\'#bo         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 18:55

    EDIT: this solution is now in the original answer too.

    The accepted answer is not quite correct. You should not be using the position() function since it is relative to the parent. If you are doing global positioning(in most cases?) you should only add the offset top with the outerheight like so:

    var actualBottom = $(selector).offset().top + $(selector).outerHeight(true);
    

    The docs http://api.jquery.com/offset/

提交回复
热议问题