Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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帮助需要Div Height_Javascript_Jquery - Fatal编程技术网

Javascript Jquery帮助需要Div Height

Javascript Jquery帮助需要Div Height,javascript,jquery,Javascript,Jquery,我试图获得我的div的自动高度,通常div框通过css160px进行设置,但是溢出:hidden;如何通过jquery检查自动高度是否超过160px 我需要这个,因为我有一个框,我有一个按钮,显示更多或显示更少,所以如果高度不大于通常的高度160px通过命令。。。现在我的盒子变小了 我的代码是: <script type="text/javascript"> $("#Show_More_Websites").click(function() { var Button_Value

我试图获得我的div的自动高度,通常div框通过css160px进行设置,但是溢出:hidden;如何通过jquery检查自动高度是否超过160px

我需要这个,因为我有一个框,我有一个按钮,显示更多或显示更少,所以如果高度不大于通常的高度160px通过命令。。。现在我的盒子变小了

我的代码是:

<script type="text/javascript">
 $("#Show_More_Websites").click(function() {
  var Button_Value = $("#Show_More_Websites").attr("value");
  var Box_Height   = $('.Box_Show_Websites').outerHeight();

  if(Button_Value == "Show More") {
   if(Box_Height <= "160") {
    var el = $('.Box_Show_Websites'),
    curHeight = el.height(),
    autoHeight = el.css('height', 'auto').height();
    el.height(curHeight).animate({height: autoHeight}, 500);
   }
   $("#Show_More_Websites").attr('value', 'Show Less');
  }

  if(Button_Value == "Show Less") {
   var el = $('.Box_Show_Websites'),
   curHeight = el.height(),
   autoHeight = el.css('height', '160px').height();
   el.height(curHeight).animate({height: autoHeight}, 500);


   $("#Show_More_Websites").attr('value', 'Show More');
  }
 });
</script> 

$(“#显示更多网站”)。单击(函数(){
var按钮_值=$(“#显示更多网站”).attr(“值”);
var Box_Height=$('.Box_Show_Websites').outerHeight();
如果(按钮_值==“显示更多”){
如果(框高度,这里是解决方案

演示提琴-注意:以下提琴仅在html部分进行了更改,以使用html

-自动高度小于
-自动高度更高


你能做一个例子吗?试着使用
$(元素)。offsetHeight
我试过了,但没有使用命令Rohit Agrawalin你的代码自动高度小于你用css给出的高度,所以它肯定会变小。因为我想知道它的自动高度有多大,我知道css中的高度是固定的(大或小)然后是自动高度,我想做的是,如果自动高度很小,那么css高度什么也不做
 $(document).ready(function() {
 $("#Show_More_Websites").click(function() {
  var Button_Value = $("#Show_More_Websites").attr("value");
  var el = $('.Box_Show_Websites')
  var Box_Height   = el.outerHeight();
  var autoHeight =  el.css('height', 'auto').height();
  el.css('height',Box_Height+'px');

  if(Button_Value == "Show More") {
    if(autoHeight > Box_Height) {
      el.height(curHeight).animate({height: autoHeight}, 500);
    }
    $("#Show_More_Websites").attr('value', 'Show Less');
  }

  if(Button_Value == "Show Less") {
    curHeight = el.height();
    autoHeight = el.css('height', '160px').height();
    el.height(curHeight).animate({height: autoHeight}, 500);
    $("#Show_More_Websites").attr('value', 'Show More');
  }
});
});