查找所有html链接的坐标

Find Coordinates of all html links

本文关键字:坐标 链接 html 查找      更新时间:2023-09-26

我使用heatmap .js来绘制点击次数最多的链接的热图。我有包含链接url和点击次数的数据,但是heatmap.js需要链接的坐标来显示数据点。得到每个连杆坐标的最佳方法是什么?

您可以使用.offset()获取链接的位置。.offset()给出的位置是相对于文档的,这意味着0,0将在页面的左上角。

//Attach a click handler to all links
$('body').on('click','a', function(event){
  //then get their offsets
  var coords = $(this).offset();
  var x = coords.left;
  var y = coords.top;
});