dongxian7194 2014-08-07 11:38 采纳率: 0%
浏览 75
已采纳

将div高度切换为自动(100%)并返回到已定义的?

I'm building movie review site using WordPress, I'm not so good with jquery or javascript, with php I can "fight". I would need some help from you guys. This is first question I actually couldn't find answer on stackoverflow, and I need it badly.

I have this code:

<div class="movie_cast">
<span class="movie_cast_bold">Cast: </span>John Hurt, Peter Mullan, Ingrid Bolsø Berdal, Ian Whyte, Robert Whitelock
</div>

My css is:

.movie_cast {
float: right;
width: 35%;
margin-left: 2%;
line-height: 15px;
font-family: 'Lucida Grande',Arial,Helvetica,Verdana,sans-serif;
font-size: 12px;
height: 20px;
overflow: hidden;
}

Whats some simple jquery with button that I can toggle my cast from height: 20px to full height height: auto, and also return after clicked back. With height of 20px it should show "more", and with full or auto height it would show "less" and return to height of 20 px.

  • 写回答

1条回答 默认 最新

  • duanjing7459 2014-08-07 11:46
    关注

    You can try this :

    $(function(){
        $('input[type="button"]').click(function(){
           var cssht = $('.movie_cast').height();
           if(cssht=='20')
               $('.movie_cast').height('auto');
            else
                $('.movie_cast').height('20px');
        });
    });
    

    Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图