Find distance between two DIVs using jQuery?

后端 未结 3 1026
灰色年华
灰色年华 2020-12-30 20:43

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

3条回答
  •  北海茫月
    2020-12-30 21:37

    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.

提交回复
热议问题