使用jQuery获取多个div的高度 [英] Get height of multiple divs with jquery

查看:374
本文介绍了使用jQuery获取多个div的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取三个div的高度,将它们加在一起,然后查看滚动位置是否大于该数字.现在我可以得到一个元素的高度,但是如何添加其他元素呢?

I need to get the height of three divs, add them together and see if the scroll position is great than that number. Right now I am able to get the height of one element, but how could I add others in?

基本上,我想写如果scroll_top大于div 1 + div 2 + 3的高度"

Basically, I want to write "if scroll_top is greater than the height of div 1 + div 2 + 3"

var scroll_top = $(window).scrollTop();

if ((scroll_top > $('.nav-bar-fixed').height()) {
    alert('sometext');
}

推荐答案

尝试一下:

$(document).ready(function() {
var limit =$('.myEle1').height() + $('.myEle2').height() + $('.myEle3').height();
   $(window).scroll(function() {
       var scrollVal = $(this).scrollTop();
        if ( scrollVal > limit ) {
           //do something.
        }
    });
 });​

此处是固定的导航示例 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆