欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取页面元素的位置

程序员文章站 2022-06-27 20:31:10
var getCoords = function(el){ var box = el.getBoundingClientRect(), doc = el.ownerDocument, body = doc.body, html = doc.documentElement, clientTop = h ......
var getcoords = function(el){
  var box = el.getboundingclientrect(),
  doc = el.ownerdocument,
  body = doc.body,
  html = doc.documentelement,
  clienttop = html.clienttop || body.clienttop || 0,
  clientleft = html.clientleft || body.clientleft || 0,
  top  = box.top  + (self.pageyoffset || html.scrolltop  ||  body.scrolltop ) - clienttop,
  left = box.left + (self.pagexoffset || html.scrollleft ||  body.scrollleft) - clientleft
  return { 'top': top, 'left': left };
};

原文地址 

上一篇: 补零

下一篇: docker三要素以及架构