简体   繁体   English

jQuery向下滑动而不是向下滑动

[英]jQuery slide down not sliding down

The slide down effect is not working. 下滑效果不起作用。 It shows the element but it does not, 'slide down'. 它显示了元素,但它没有,“向下滑动”。

HTML: HTML:

        <div class='settings'>
            <h4>Account Settings</h4>
            <table class='options'>
                <tr>
                    <td class='name username'>Name</td>
                    <td class='value'>Robert Rocha</td>
                    <td class='edit editName'><a href='#'>Edit</a></td>
                </tr>
                <!-- edit name -->
                <tr class='hidden name-edit'>
                    <td colspan='3'>
                        <table class='edit-name'>
                            <tr>
                                <td class='first'><label for='fname'>First</label></td>
                                <td><input type='text' name='fname' class='fname' id='fname'></td>
                            </tr>
                            <tr>
                                <td class='last'><label for='lname'>Last</label></td>
                                <td><input type='text' name='lname' class='lname' id='lname'></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td colspan='2'class='commit'><a href='#' class='save'>Save</a><a href='#' class='cancel'>Cancel</a></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class='name email'>Email</td>
                    <td class='value'>tom@gmail.com</td>
                    <td class='edit'><a href='#'>Edit</a></td>
                </tr>
                <!-- edit email -->
                <tr  class='hidden'>
                    <td colspan='3' class='edit-email'><label for='email'>Email</label><input type='email' name='email' id='email'><a href='#' class='save'>Save</a><a href='#' class='cancel'>Cancel</a></td>          
                </tr>
                <tr>
                    <td class='name pword' colspan='2'>Password</td>
                    <td class='edit'><a href='#'>Edit</a></td>
                </tr>
                <!-- edit password -->
                <tr  class='hidden'>
                    <td colspan='3' class='edit-password'><label for='pword'>Password</label><input type='password' name='pword' id='pword'><a href='#' class='save'>Save</a><a href='#' class='cancel'>Cancel</a></td>
                </tr>
                <tr>
                    <td class='name remove-all' colspan='3'><a href='#'>Delete All Photos</a></td>
                </tr>
                <tr>
                    <td class='name remove-account' colspan='3'><a href='#'>Delete Account</a></td>
                </tr>
            </table>

        </div>
        <!-- end settings -->

CSS: CSS:

.hidden { display: none; }

/* Settings */

.settings {
    width: 650px;
    margin: 0 auto;
    padding: 1em;
}

.settings h4 {
    padding: 1em 0;
    letter-spacing: 1px;
    border-bottom: 1px solid #cacece;
}

table {
    font-size: 0.9em;
    letter-spacing: 1px;
    font-weight: 200;
}

table.options { 
    width: 100%;
    table-layout: fixed;
}

.options tr { border-bottom: 1px solid #cacece; }
.options td { padding: 0.5em 0; }
.options .edit { text-align: right; }
.options .name { font-weight: bold; }
.options .remove-all, .options .remove-account { font-weight: 200; }

/* Edit Name Table */

table.edit-name {
    width: 300px;
    font-size: 0.9rem;
    margin: 0 auto;
}

.edit-name tr { border: none; }
.edit-name .save, .cancel { margin-left: 10px; }

/* Edit Table */

input[type='email'],
input[type='password'],
.edit-email .save,
.edit-email .cancel,
.edit-password .save,
.edit-password .cancel
{ margin-left: 15px; }

.edit-email, .edit-password { text-align: center; }

jQuery: jQuery的:

$('.options .editName a').on('click', function(e) {
    e.preventDefault();
    $('.name-edit').slideDown('slow');
});

Result: https://jsfiddle.net/ekL6450a/ 结果: https//jsfiddle.net/ekL6450a/

Animations are not supported on table rows, you can consider to wrap your table in a div and apply the animation on that div . 不支持动画上表中的行,你可以考虑来包装你表中一个div和应用上的动画div

From "Learning jQuery" 来自“学习jQuery”

Table rows present particular obstacles to animation, since browsers use different values (table-row and block) for their visible display property. 表行为动画提供了特定的障碍,因为浏览器使用不同的值(表行和块)作为其可见的显示属性。 The .hide() and .show() methods, without animation, are always safe to use with table rows. 没有动画的.hide()和.show()方法始终可以安全地与表行一起使用。 As of jQuery version 1.1.3, .fadeIn() and .fadeOut() can be used as well. 从jQuery版本1.1.3开始,也可以使用.fadeIn()和.fadeOut()。

You're working with tables... Switch to a tableless approach and it'll work. 你正在使用表格...切换到无表格的方法,它会工作。 I've updated your fiddle with an example: 我用一个例子更新了你的小提琴:

Html HTML

<div class='settings'>
            <h4>Account Settings</h4>
      <div class="options">
        <span class="name username">Name</span>
        <span class="value">Robert Rocha</span>
        <span class="edit editName"><a href="#">Edit</a></span>
      </div>
      <div class="hidden name-edit">
        <div>
          <label for='fname'>First</label><br>
          <input type='text' name='fname' class='fname' id='fname'><br>

        </div>
      </div>
</div> 
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>

Javascript 使用Javascript

$('.options .editName a').on('click', function(e) {
    e.preventDefault();
    $(this).parent().parent().next('.name-edit').slideToggle('slow');
});

the problem is with the nature of TR tag. 问题在于TR标签的性质。 slideDown works well with elements that is of display:block; slideDown适用于display:block;

Just for fun, if you add 只是为了好玩,如果你添加

tr{
    display: block;
}

before the css for your .hidden, you will realize that slideDown works. 在你的.hidden的css之前,你会发现slideDown有效。

see fiddle enter link description here 看小提琴在这里输入链接描述

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

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