zoukankan      html  css  js  c++  java
  • 如何获得div对象的绝对坐标

    <script>

                function test() {

                    var $div0 = $('#0');

                    var $div1 = $('#1');

                    var $div2 = $('#2');

                    var h0 = $div0.offset().top + $div0.height();

                    var h1 = $div1.offset().top + $div1.height();

                    var h2 = $div2.offset().top + $div2.height();

                    console.log($div0.offset().top + '+' + $div0.height() + '=' + h0);

                    console.log($div1.offset().top + '+' + $div1.height() + '=' + h1);

                    console.log($div2.offset().top + '+' + $div2.height() + '=' + h2);

                }

            </script>

     

    在 Chrom 或 Firefox 中点击 F12:

     

    注意 jQuery 的 .offset() 只有 .top 和 .left 属性,没有right 和 bottom 属性,需要right的话可以使用本文例子的方法计算。

  • 相关阅读:
    分治6--循环比赛日程表
    分治5--一元三次方程求解
    分治4--快速排序
    分治3--黑白棋子的移动
    分治2--取余运算
    分治1--二分查找
    贪心6--整数区间
    贪心5--活动选择
    贪心4--拦截导弹
    贪心3--删数问题
  • 原文地址:https://www.cnblogs.com/my4piano/p/5407284.html
Copyright © 2011-2022 走看看