使用jQuery找到两个DIV之间的距离? [英] Find distance between two DIVs using jQuery?
本文介绍了使用jQuery找到两个DIV之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个DIV,我需要知道他们计算出的浏览器距离(高度)。
我已阅读过有关偏移功能的信息,但这些示例并未针对我尝试这样做的方式编写。
示例用法:
< div class =foo>< / div>
< div class =bar>< / div>
我想知道这两者之间的距离。
请帮助我用jQuery动态地查找距离。
解决方案
类似这样的应用程序:
$ b $ $ $ $ $ $ $'$ f $'。offset()。top - $('。bar')。offset()。top
只要每个类在页面上只有一个元素。
如果它们不是独特的,给这两个元素一个ID和参考。
I have two DIVs that I need to know the calculated browser distance (in height) of them. I have read about the offset feature but the examples were not written for the way I am trying to do this.
Example usage:
<div class="foo"></div>
<div class="bar"></div>
I want to know the distance between these two.
Please help me to find the distance dynamically with jQuery.
解决方案
Something like this should work:
$('.foo').offset().top - $('.bar').offset().top
As long as each class only has one element on the page.
If they are not unique, give the two elements an ID and reference with that.
这篇关于使用jQuery找到两个DIV之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文