• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
雁飞残月天凯
博客园    首页    新随笔    联系   管理    订阅  订阅

jquery获取文档元素坐标值

  <!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
  /**{
  margin: 0;
  padding: 0;
  }*/
  div{
  width: 800px;
  height: 800px;
  border:1px solid #eee;
  position: relative;
  margin: 50px;
  }
  img{
  position: absolute;
  top: 50px;
  left: 80px;
  }
   
  </style>
  <script src='js/jquery-1.11.3.min.js'></script>
  <script>
  $(function(){
  $('button:eq(0)').click(function(){
  alert($('.box').offset().top + ',' + $('.box').offset().left);
  })
  $('button:eq(1)').click(function(){
  alert($('img').position().top+ ',' + $('img').position().left);
  })
  })
  </script>
  </head>
  <body>
  <button>获取div的文档坐标值</button>
  <button>获取图片相对于定位点的坐标值</button>
  <div class='box'><img src="images/lunbo/0.jpg" alt=""></div>
  </body>
  </html>
posted @ 2019-08-21 19:46  雁飞残月天凯  阅读(191)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3