Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery和Ajax加载上的奇怪变量值_Javascript_Jquery_Css - Fatal编程技术网

Javascript jQuery和Ajax加载上的奇怪变量值

Javascript jQuery和Ajax加载上的奇怪变量值,javascript,jquery,css,Javascript,Jquery,Css,我有这个密码 var varheight; $('.item-content').load("content/content.html", function(){ varheight = $('.item-content').css('height'); $('.item-content').css({height: 0}); $('.item-content').animate({'height': varheight}, 1000); }); 我希望它做的是将内容加

我有这个密码

var varheight;
$('.item-content').load("content/content.html", function(){
    varheight = $('.item-content').css('height');
    $('.item-content').css({height: 0});
    $('.item-content').animate({'height': varheight}, 1000);
});
我希望它做的是将内容加载到容器中,这样我可以在加载后获得容器的总大小,然后在用户看到之前将高度设置为0,然后通过动画慢慢地将高度增加到它的大小

看起来很直截了当,代码应该能正常工作。。。但是,奇怪的事情正在发生。。。如果我用如下警告检查
varheight
的值:

var varheight;
$('.item-content').load("content/content.html", function(){
    varheight = $('.item-content').css('height');
    alert(varheight);
    $('.item-content').css({height: 0});
    $('.item-content').animate({'height': varheight}, 1000);
});
我得到0。不应该这样,因为我刚刚在.item内容中加载了很多内容

奇怪的是,如果我删除下面两行,就像这样:

var varheight;
$('.item-content').load("content/content.html", function(){
    varheight = $('.item-content').css('height');
    alert(varheight);
});
我得到了真实的值(大约1300px,这不是这里真正重要的一点)

我不禁想知道,即使这些线还没有达到,这个值怎么会改变呢?如果该变量的值不再更改,而且最糟糕的是,警告出现在这些行之前,它们如何影响该变量的值


我在这里发疯了

显然,有另一个并行脚本正在运行,它在这个脚本之前将高度硬编码为0,导致了问题


脚本已删除,问题已解决。

已尝试。。。不走运。完全相同的行为:/好吧,看起来维加删除了它的评论,但他是对的!代码的另一部分出现问题,导致高度硬编码为0!修好了,现在一切正常!将您的解决方案作为答案发布并接受:)