CSS过渡可调高度

时间:2012-09-18 03:08:04

标签: jquery css button html transitions

我发现这个How can I transition height: 0; to height: auto; using CSS?并且我一直在尝试使用此方法来更改按钮onclick上div的高度,但由于某种原因它不适合我。对不起,如果有很多不必要的信息。

的jQuery

function playSound(soundfile){
      document.getElementById("dummy").innerHTML = 
      "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}

   $('button').bind('click', function(e) {
         e.preventDefault();

   $('.taller').toggleClass('animated');
   });

HTML

  <div id="container">
     <span id="dummy"></span>
     <button onclick="playSound('sound/button-30.wav','sound/button30.mp3');">PlaySound</button>                         
     <div class="taller">I SHOULD BECOME TALLER</div>
  </div>

CSS

#container{
background-color:lightblue;
width:960px;
height:550px;
}

.taller{
overflow:hidden;
background:#000;
color:#fff;
width:80px;
max-height:15px;
-webkit-transition: max-height .5s linear;
-moz-transition: max-height .5s linear;
transition: max-height .5s linear;
}

.animated{
max-height:100px;
}

2 个答案:

答案 0 :(得分:0)

我将您的代码放入jsfiddle并进行测试。它运作得很好;我没有做任何事情。您可以在http://jsfiddle.net/WY7gM/

中查看您的代码

答案 1 :(得分:0)

这是你要找的吗?

<强> Live Demo

将其更改为高度而不是最大高度,并且工作正常。在切换时,它会增长/缩小。你的问题有点模糊,所以我不确定这是不是你的追求。另外为什么不把playound功能放在click bind中呢?

相关问题