`
vincent_com
  • 浏览: 42335 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类

获取div的页面位置

 
阅读更多

<style type="text/css">
 body { margin:0px; }
 .map { width:100px; height:100px; position:absolute; background-color:#476D78; position:absolute; top:200px; left:500px; }
</style> 
<script type="text/javascript">
 document.onmousedown=function(){
  // 获取当前div的坐标
  var div=document.getElementById("mydiv");
  var top,left;
  if(div.currentStyle){left=div.currentStyle.left;top=div.currentStyle.top;}
  else if(window.getComputedStyle){left=window.getComputedStyle(div,null).left;top=window.getComputedStyle(div,null).top;}
  alert(left+","+top);
 }
</script>
<div class="map" id="mydiv">
 asdfasdfasdfasdf
</div> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics