Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
jquery重置和设置变量_Jquery_Variables - Fatal编程技术网

jquery重置和设置变量

jquery重置和设置变量,jquery,variables,Jquery,Variables,我试图创建具有可变“顶部”高度的slideUp div,这样一个div可以滑动700px,而另一个(内容较少)只能滑动400px。目前,div都在同一高度滑动。css中没有div高度声明。我的剧本: $(document).ready(function(){ var oldHeight; $('a.menubtn').click(function(){ var newHeight;

我试图创建具有可变“顶部”高度的slideUp div,这样一个div可以滑动700px,而另一个(内容较少)只能滑动400px。目前,div都在同一高度滑动。css中没有div高度声明。我的剧本:

$(document).ready(function(){          
            var oldHeight;  
    $('a.menubtn').click(function(){              
            var newHeight;
            if ($(this.id) == 'work') {
                  newHeight = 700;  
                  }
                  else { if ($(this.id) == 'services') {
                      newHeight = 400;
                  }
                  else { if ($(this.id) == 'about') {
                      newHeight = 400;
                  }
                  else {
                      newHeight = 300;
                  }
                  }
                  }

            if ($('.active').length > 0) {

                $('.active').removeClass('active').animate({'top': '+=' + oldHeight + 'px'}, '200');
                $('div#contents_'+ this.id).addClass('active').animate({'top': '-=' + newHeight + 'px'}, '200');
                oldHeight = newHeight;
                }
                else 
    $('div#contents_'+ this.id).addClass('active').animate({'top': '-=' + newHeight + 'px'}, '200');
                oldHeight = newHeight;
                }
    return(false);
    });               
})

TIA.

如果您的
陈述有误,请告知您的

这:

应该是:

this.id == 'work'     // here you're comparing the actual ID value to 'work'
如果将
if
语句的结构更改为如下所示,则会更干净:

if (this.id == 'work') {
    newHeight = 700;  
} else if (this.id == 'services') {
    newHeight = 400;
} else if (this.id == 'about') {
    newHeight = 400;
} else {
    newHeight = 300;
}
if (this.id == 'work') {
    newHeight = 700;  
} else if (this.id == 'services') {
    newHeight = 400;
} else if (this.id == 'about') {
    newHeight = 400;
} else {
    newHeight = 300;
}