IE、FireFox3以及更高版本和Opera9.5以及更高版本都提供了getBoundingClientRect()方法,这个方法返回一个矩形对象,left、top、right、bottom,这些属性返回的是节点相对于浏览器(0,0)坐标(节点相对于视口的位置)的位置。但IE认为文档的左上角坐标是(2,2),而FireFox Opera则将传统的(0,0)作为起点坐标,因此开始的时候,检查一下位于(0,0)的位置。

 demo:

<div >var t = offset(m);
alert('top:' + t.top + '\n' + 'left:' + t.left + '\n' + 'right:' + t.right + '\n' + 'bottom:' + t.bottom);

</script>

 参考:javascript高级程序设计第二版

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2021-05-27
  • 2021-09-07
  • 2021-07-13
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
猜你喜欢
  • 2021-12-25
  • 2021-06-13
  • 2022-12-23
  • 2021-09-07
  • 2021-10-10
  • 2021-07-20
相关资源
相似解决方案