jQuery x y document coordinates of DOM object

前端 未结 3 1884
陌清茗
陌清茗 2020-11-27 13:36

I need to get the X,Y coordinates (relative to the document\'s top/left) for a DOM element. I can\'t locate any plugins or jQuery property or method that can give these to

3条回答
  •  悲哀的现实
    2020-11-27 14:14

    The offset function will do that for you.

    Here is the example they give:

    var p = $("p:last");
    var offset = p.offset();
    p.html( "left: " + offset.left + ", top: " + offset.top );
    

提交回复
热议问题