admin管理员组文章数量:1303450
i'm having trouble animating a div expanding. My JQuery function does what it's supposed to, but the animation doesn't appear. I have tried both transition : all
and transition : max-height
but none seems to work. Also something very weird happens, when i want to hide my div again. It appears that there's some kind og delay before it disappears. This delay matches the time of the animation, but i can't figure out what's wrong. Please help.
Here's a fiddle: /
i'm having trouble animating a div expanding. My JQuery function does what it's supposed to, but the animation doesn't appear. I have tried both transition : all
and transition : max-height
but none seems to work. Also something very weird happens, when i want to hide my div again. It appears that there's some kind og delay before it disappears. This delay matches the time of the animation, but i can't figure out what's wrong. Please help.
Here's a fiddle: https://jsfiddle/vbqc2c27/1/
Share asked Mar 30, 2016 at 10:15 JohnDoeJohnDoe 5451 gold badge8 silver badges23 bronze badges 03 Answers
Reset to default 4You can't animate from a specific value (0px) to a relative value (100%). You need to use specific values:
Updated fiddle
$("p").on("click",function() {
if($("#test").css("max-height") == "0px") {
$("#test").css("max-height","100px");
}
else {
$("#test").css("max-height","0px");
}
});
Change "100%" to "100px" and it works fine.
Of course, for that paragraphs 100px isn't tall enough (the text is clipped). So you may need to add a function to calculate the auto-height in pixels.
Updated fiddle - simple solution without delay
Fix delay solution:
Put cubic-bezier(0, 1, 0, 1) transition function for element.
.text {
overflow: hidden;
max-height: 0;
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
&.full {
max-height: 1000px;
transition: max-height 1s ease-in-out;
}
Or you can use slideToggle()
function which is much more simplier than that :)
See this fiddle
JS
$("p").on("click",function() {
$("#test").slideToggle();
});
CSS
div {
display: none;
}
本文标签: javascriptmaxheight transition doesn39t work and works slowStack Overflow
版权声明:本文标题:javascript - max-height transition doesn't work and works slow - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741688973a2392609.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论