【问题标题】:Show a hidden element and then animate it显示一个隐藏的元素,然后对其进行动画处理
【发布时间】:2016-12-18 05:09:42
【问题描述】:

在隐藏类.button 之后,如何使隐藏的form 从右到左动画。我可以制作类似的东西,但我无法同步它们的动画。
button被点击时,它会向右移动一些像素然后被隐藏,在它被隐藏之前,我想让form动画。

如何创建与.button 类中的表单相同的效果,并从那里出现?

非常感谢任何帮助!

这里是小提琴:fiddle link

【问题讨论】:

标签: jquery html css


【解决方案1】:

试试这个fiddle更新 在本例中,我们使用CSS3 动画。

【讨论】:

    【解决方案2】:

      $('a.button').click(function() {
        $(this).addClass('hidden-btn');
        $('.myform').fadeIn('slow');
        $('.myform input').focus();
      });
    .wrapper {
      overflow: hidden;
      height: 200px;
    }
    .button {
        font-size: 18px;
        background-color: lightblue;
        width: 222px;
        text-align: center;
        height: 44px;
        line-height: 40px;
        text-transform: uppercase;
        display: inline-block;
        font-weight: 700;
        margin-top: 100px;
        left: 50%;
        transform: translateX(-50%);
        position: relative;
        transition: all 0.4s
    }
    .hidden-btn {
      left: 200%;
    }
    .myform {
        float: left;
        position: relative;
        margin-top: 100px;
        display: none;
        left: 50%;
        top: -145px;
        transform: translateX(-50%);
    }
    .myform input {
        float: left;
        width: 284px;
        height: 40px;
        padding-left: 63px;
        padding-right: 5px;
        margin-top: 1px;
        border: none;
        color: #767676;
        font-size: 13px;
        background-color: lighgrey;
    }
    .myform button {
         width: 170px;
        height: 44px;
        border: 0;
        text-transform: uppercase;
        color: #fff;
        font-size: 16px;
        background-color: lighblue;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="wrapper">
      <a href="#" class="button">Test</a>
      <form class="myform" action="">
        <input type="text" placeholder="Email">
        <button type="submit">try</button>
      </form>
    </div>

    【讨论】:

    • 感谢您的回复!但是,当单击按钮被隐藏时,我需要隐藏元素动画在同一位置开始
    • 他们现在位置相同,我更新了答案..刚刚调整了.myform { top: -145px;}属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多