Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 扩展压缩div_Javascript_Jquery - Fatal编程技术网

Javascript 扩展压缩div

Javascript 扩展压缩div,javascript,jquery,Javascript,Jquery,当我点击它时,它可以展开div。如何添加“查看更多”链接,然后在div扩展时将其隐藏,并相对于“查看更多”链接调整行高,从而使其看起来更漂亮 $(document).ready(function(){ var rowsshown = 2; var rowheight = 1.2; // line height in 'em' var ht = (rowsshown * rowheight) - .5; // subtracting the .5 prevents the top of th

当我点击它时,它可以展开div。如何添加“查看更多”链接,然后在div扩展时将其隐藏,并相对于“查看更多”链接调整行高,从而使其看起来更漂亮

$(document).ready(function(){
 var rowsshown = 2;
 var rowheight = 1.2; // line height in 'em'
 var ht = (rowsshown * rowheight) - .5; // subtracting the .5 prevents the top of the next line from showing
 $('.info')
  .css({'overflow':'hidden','line-height' : rowheight + 'em','height': ht + 'em' })
  .click(function(){
   if ( $(this).css('height') == 'auto') {
    $(this).css('height', ht + 'em');
   } else {
    $(this).css('height','auto');
   }
  });
})

您可以查看jqueryslideup和slidedown


为了获得更好的效果,您可以查看jquery slideup和slidedown

要获得更好的效果,请尝试:

试试:


我把它们放在一个循环中,我该怎么办?当我点击“查看更多”时,其余的也会展开。我让它们在一个循环中,我该怎么办?当我点击“查看更多”按钮时,其他按钮也会展开。