脚本分析DIV高度无效 [英] Script analysing DIV height non function

查看:84
本文介绍了脚本分析DIV高度无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下似乎无法使用的脚本.

I have the following script that is not appearing to work.

var height = $('#sidebar1').height();
var pageHeight = $(window).height();

if ((height) > 600) {
  alert('haha');
}

此脚本的不可避免的后果是让它针对pageHeight而不是600进行解析,但是即使使用600,我也无法使其正常工作.

The ineveitable conlcusion to this script is to have it analayse against pageHeight rather than 600, but I cannot get this to work even with 600.

我只能得出结论,这与div: #sidebar1是浮动的棍子元素有关.这是它的CSS.

I can only conclude it is something to do with this div: #sidebar1 being a floaty stick element. Here is its CSS.

.sidebar { float: right; width: 190px; padding-top:8px; }

脚本是加载的一部分,根据表单中的选择,div: #sidebar1的高度将随着加载内容而扩展.

The script is part of a load whereby the div: #sidebar1 's height expands as content is loaded in based on choices in a form.

任何想法,

奇妙

通过将警报作为元素的高度包括在内,我们现在可以看到该高度被卡在"430",即使它似乎在继续扩展. 任何想法

EDIT : From including the alert as the height of the element we can see now that the height gets stuck at '430' even though it seemingly continues to expand. Any ideas

推荐答案

我尝试了以下对我有用的方法.检查 div元素的idclass属性,并确保内容实际上大于600(高度),您可以尝试添加else语句以查看高度:

I tried the following which works for me. Check the id and class attributes for the div element, and make sure the content is actually greater than 600 (height) you can try adding an else statement to see your height:

$(document).ready(function(e) {
var height = $('#sidebar1').height();
var pageHeight = $(window).height();

    if ((height) > 600) {
        alert('haha');
    }

    else {
        alert(height);
    }
});


.sidebar { 
    float: right; 
    width: 190px; 
    padding-top:8px; 
}


<div id="sidebar1" class="sidebar">
    <img src="SomeContent.png" width="190" height="601" />
</div>

这篇关于脚本分析DIV高度无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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