Element coordinates in pure Javascript

后端 未结 3 1742
梦谈多话
梦谈多话 2021-01-13 08:14

Say that I have an element inside a div (or any other containing element, or perhaps just in the body of the document). How do I get the (x,y) coordinates of that element, r

3条回答
  •  囚心锁ツ
    2021-01-13 08:58

    Use the below

    document.getElementById("elementId").offsetTop;
    document.getElementById("elementId").offsetLeft;
    

提交回复
热议问题