gpt4 book ai didi

javascript - 为什么 css transition 会延迟工作

转载 作者:搜寻专家 更新时间:2023-10-31 08:54:13 24 4
gpt4 key购买 nike

因此,我使用 js 触摸我的类别列表的 css 属性“max-height”。在第一种情况下,当列表未完全打开时,转换工作正常。在第二种情况下,当我需要隐藏列表的某些部分时,css 转换会像延迟一样开始。

    .category_list>ul {
display: inline-block;
text-align:left;
overflow: hidden;
word-wrap: break-word;
width: 170px;
transition: max-height 1s ease-out;
-webkit-transition: max-height 1s ease-out;
-moz-transition: max-height 1s ease-out;
-o-transition: max-height 1s ease-out;
}

$('body').on('click','.full_category_list>span',function(){
if ($(this).text()=='open list') {
$(this).parent().parent().find('ul').stop().css('max-height','500px');
$(this).text('hide list');
} else {
var ul = $(this).parent().parent().find('ul');
console.log($(ul).attr('data-height'));
$(ul).stop().css('max-height',$(ul).attr('data-height'));
$(this).text('open list');
}
});

怎么说现在列出隐藏?请帮我 :)喜欢在这里摆弄fiddle

最佳答案

所以,决定就是这么简单!需要打开其 child 的高度总和列表。正确的代码:

    $('body').on('click','.full_category_list>span',function(){
if ($(this).text()=='open list') {
var ul = $(this).parent().parent().find('ul');
$(ul).stop().css('max-height',$(ul).attr('data-fullheight'));
$(this).text('hide list');
} else {
var ul = $(this).parent().parent().find('ul');
$(ul).stop().css('max-height',$(ul).attr('data-height'));
$(this).text('open list');
}

});

喜欢更新的 fiddle fiddle

谢谢@vel!!!

关于javascript - 为什么 css transition 会延迟工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30498885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com