简体   繁体   English

CSS3动画-在类上向左移动不起作用

[英]CSS3 Animations - Move Left on class add not working

I'm currently looking in to and learning how to properly do CSS3 Animations and I've run in to a bit of trouble. 我目前正在研究并学习如何正确地制作CSS3动画,但遇到了一些麻烦。 I have a box currently sitting in the horizontal center of the page, and I'd like to have it move to the left with a transition when a class is applied to it. 我当前在页面的水平中心有一个框,当将类应用于该框时,我希望它向左移动并带有过渡。

characterBox is already attached to the div when the page loads. 页面加载时characterBox已附加到div。 When I add characterActive to the div with jQuery though, it moves directly to the left without the transition. 当我使用jQuery将characterActive添加到div时,它直接移到左侧而不进行过渡。 What am I doing wrong? 我究竟做错了什么? Any help is appreciated! 任何帮助表示赞赏!

.characterActive {
    left: 15px;
    position: absolute;
}
.characterBox {
    display: inline-block;
    padding-left: 8px;
    padding-right: 8px;
    padding-top: 15px;
    -webkit-transition: left 0.5s ease;
    -moz-transition: left 0.5s ease;
    -o-transition: left 0.5s ease;
    -ms-transition: left 0.5s ease;
    transition: left 0.5s ease;
/* Sit Horizontally */
    margin: auto;
    text-align: center;
}

You are switching from static to absolute positioning by adding that class, which is ok, but there's nothing to transition from because the left value from the static element is auto (transitions from/to automatic values are not reliable, see this bug report ) 您可以通过添加该类从静态定位切换到绝对定位,这是可以的,但是没有任何要过渡的内容,因为静态元素的left值为auto (从/到自动值的转换不可靠,请参见此错误报告

So add: 因此添加:

.characterBox{
  left: 0px;
}

Also you have to switch the order of the definitions, because your 2nd left rule would override the first ( http://jsfiddle.net/yLgkK/ ) 另外,您还必须切换定义的顺序,因为left第二个规则将覆盖第一个( http://jsfiddle.net/yLgkK/

It looks like that it doesnt work with the property left . 看来它与left的属性不起作用。 try to use margin-left instead. 尝试改用margin-left

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

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