CSS animation doesn't work changing top value

点点圈 提交于 2019-12-24 16:19:12

问题


With this JQuery I change the vertical position of the form, but I have ta problem with the animation: I would like to animate the change of the position, so the user can see the input field moving to the new position. Why doesn't the animation work?

http://jsfiddle.net/p6m97gwb/

If it is possible, I would like to use animate.css

HTML

<div id="searchMainWrapper">
    <div id="searchMain" class="vertical-align-middle">
        <form>
            <input type="text">
        </form>
    </div>
</div>

CSS

#searchMainWrapper {
    -webkit-animation: animate 3s; /* Safari and Chrome */
       -moz-animation: animate 3s; /* Firefox */
            animation: animate 3s;
    -webkit-transform-style: preserve-3d;
       -moz-transform-style: preserve-3d;
            transform-style: preserve-3d;

    position: absolute;
    width: 100%;
    height: 100%
}

.vertical-align-middle {
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}
.vertical-align-top {
    position: relative;
    top: 0px;
}

JS

$('#searchMain').removeClass('vertical-align-middle').addClass('vertical-align-top');

回答1:


Use transition instead of animate

demo

#searchMain{
    position:absolute;
    transition: 3s;
}
.vertical-align-middle {
    top: 50%;
}
.vertical-align-top {
    top: 0px;
}


来源:https://stackoverflow.com/questions/32798939/css-animation-doesnt-work-changing-top-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!