首页 > 其他 > 详细

如何获得div对象的绝对坐标

时间:2016-04-19 11:35:02      阅读:140      评论:0      收藏:0      [点我收藏+]

<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的话可以使用本文例子的方法计算。

如何获得div对象的绝对坐标

原文:http://www.cnblogs.com/my4piano/p/5407284.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!