javascript - $.animate() jQuery显示:table without affecting unspecified spatial dimensions

标签 javascript jquery css jquery-animate css-tables

display:table 上使用 jQuery 的 $.animate() 时,未指定要更改的空间尺寸将会产生动画效果。

fiddle

在本例中,指定了 width,但未指定 height,但 height 会跳转。在这种情况下,如何防止 display:tableheight 在视觉上发生变化?

html

<div style="display:table; height:40px;">
    <div style="display:table-row">
        <div class="cell">
            Short text
        </div>
        <div class="cell cellToAnimate">
            Really long text
        </div>
        <div class="cell cellToAnimate">
            Really, really, really long text
        </div>
    </div>
</div>
<div>
<button type="button" id="cellChanger">Change cells</button>

CSS

.cell{
    display:table-cell;
}

js

$(文档).ready(函数(){

$('.cellToAnimate').hide();

$("#cellChanger").click(function(){
    $('.cellToAnimate').stop(true,false).animate({
        width: 'toggle',
        opacity: 'toggle'
    });
});

});

最佳答案

为容器设置样式

display: block;
height: 40px;
overflow: hidden;

关于javascript - $.animate() jQuery显示:table without affecting unspecified spatial dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032552/

相关文章:

Javascript createImageData 抛出 DOM 异常 9,rgb 数据不工作

javascript - html 页面中显示错误#2032

html - flexbox 中最小尺寸的内容

css - Chrome 中的网络字体

html - H1 标签不再显示在页面主体上

javascript - jQuery Validate 似乎将无效表单传递给submitHandler

javascript - 恢复使用parentNode.removeChild删除的项目

javascript - 制作类似facebook的悬停弹出框效果

php - 使用 PHP 和 MySQL 的 jQuery 倒计时

javascript - 渲染前移除 HTML 属性