Get bottom and right position of an element

后端 未结 7 876
遇见更好的自我
遇见更好的自我 2020-12-01 00:45

I\'m trying to get the position of an element within the window like so:

var link = $(element);

var offset = link.offset();
var top = offset.top;
var left =         


        
7条回答
  •  悲&欢浪女
    2020-12-01 01:17

    Instead of

    var bottom = $(window).height() - link.height();
    bottom = offset.top - bottom;
    

    Why aren't you doing

    var bottom = $(window).height() - top - link.height();
    

    Edit: Your mistake is that you're doing

    bottom = offset.top - bottom;
    

    instead of

    bottom = bottom - offset.top; // or bottom -= offset.top;
    

提交回复
热议问题