简体   繁体   English

jQuery切换动画播放不流畅吗?

[英]jQuery toggle animation not playing smooth?

Here is the JSFiddle 这是JSFiddle

Look at the animation, the gray background div expands and collapses with jerk (without animation). 看一下动画,灰色背景div会突然移动(没有动画)而折叠。

Can anyone help me out. 谁能帮我吗。

HTML: HTML:

<div class="referrals-data">
<div class="data-contner">

<div class="table-elmnt">
<div class="referral-band row-elmnt">
    <div class="clearfix cell-elmnt">
        <div class="referral-id have-referrals">
            <span class="referral-pic"></span>
            <span class="referral-name">Click me</span>
        </div>
    </div>
    <div class="cell-elmnt">
    $2000
    </div>
    <div class="cell-elmnt">
    $50
    </div>
</div> <!--referral-band-->

    <div class="my-referral">
        <div class="referrals-data sub-referral">
            <div class="table-elmnt">
                <div class="referral-band row-elmnt">
                    <div class="clearfix cell-elmnt">
                        <div class="referral-id">
                            <span class="referral-pic"></span>
                                <span class="referral-name">User</span>
                        </div>
                    </div>
                    <div class="cell-elmnt">
                        $2000
                    </div>
                    <div class="cell-elmnt">
                        $50
                    </div>
                </div> <!--referral-band-->
            </div> <!--table-elmnt-->
        </div>         
    </div> <!--my-referral-->
</div> <!--table-elmnt-->

jQuery jQuery的

$('.my-referral').hide();
    $('.have-referrals').click(function () {
        if($(this).parent().parent().parent().parent().children('.my-referral').css('display') == 'none'){
            $(this).addClass('show');
        }else{
            $(this).removeClass('show');
        };
        $(this).parent().parent().parent().children('.my-referral').slideToggle();
    });

CSS 的CSS

.table-elmnt { display: table; width: 100%; }
.row-elmnt { display: table-row; width: 100%; padding: ; } 
.cell-elmnt { display: table-cell; width: 15%; vertical-align: top; padding: 7px 10px; } 
.cell-elmnt:first-child { width: 70%; }
.referrals-data { margin-bottom: 7px; }
.data-contner { background: #d4d4d4; }
.my-referral { padding-left: 25px; }
.sub-referral { margin-bottom: 0; border-bottom: none; }
.referral-id { float: left; padding-left: 20px; }
.referral-pic { padding: 2px; border-radius: 100px; background: #ffffff; width: 25px; height: 25px; display: inline-block; overflow: hidden; vertical-align: middle; text-align: center; }
.referral-name { display: inline-block; vertical-align: middle; margin-left: 7px; }
.have-referrals { cursor: pointer; }

将“ Speed”参数与slideToggle()配合使用:

 $(this).parent().parent().parent().children('.my-referral').slideToggle("slow");

It would appear as if displaying the divs as table rows and cells is at the heart of the issue. 似乎将div作为表行和单元格显示是问题的核心。 If you remove those properties and instead display as an inline-block it works perfectly: 如果删除这些属性,而是显示为行内块,则效果很好:

http://jsfiddle.net/V5zL8/3/ http://jsfiddle.net/V5zL8/3/

.table-elmnt {
    width: 100%;
}
.row-elmnt {
    width: 100%;
}
.cell-elmnt {
    width: 15%;
    vertical-align: top;
    padding: 12px 0;
    display: inline-block;
}
.cell-elmnt:first-child {
    width: 68%;
    padding: 7px 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM