【问题标题】:transform: scale(x,x) doesn't work on animation in Firefoxtransform: scale(x,x) 不适用于 Firefox 中的动画
【发布时间】:2014-04-25 12:21:54
【问题描述】:

我正在尝试使用滑块在 Firefox 中“转换:缩放(x,x)”一个 css3“动画”。如果我关闭动画,滑块和缩放工作。如果我打开动画,它会动画,但缩放不起作用。

这是我的 jsfiddle... 如果您取消注释 CSS 的末尾,您可以看到问题。我希望箭头旋转和缩放。

(仅限 FIREFOX,下面是 chrome/safari 链接):http://jsfiddle.net/G6rYu/

$("#slider-step").on("change", function(e){
    scale= $("#slider-step").val() / 100;

    $(".elem.A").css("transform", "scale("+scale+","+scale+")");
    $(".elem.B").css("transform", "scale("+(1-scale)+","+(1-scale)+")");
});

还有……

.elem.A {  
    background-image:url('http://s24.postimg.org/ua9mzwmht/arrow.png');

    animation-name: rotate; 
    animation-duration: 3.0s; 
    animation-iteration-count: infinite;
    animation-timing-function: linear;
 }
 @keyframes rotate {
    from {transform: rotate(0deg);}
    to {transform: rotate(-360deg);} 
}

这是我想要的效果(仅适用于 Chrome / Safari):http://jsfiddle.net/nick2ny/4mLkU/

【问题讨论】:

  • 您确定可以在单个元素上使用多个变换吗?当您应用transform: rotate() 时,它应该只覆盖第一个transform: scale()。对于 Chrome,您使用缩放,所以我猜没有冲突。
  • 我认为你可能是对的。我将尝试这样做,并使用 webkit 和无前缀 css3,并使用包装器,就像你建议的那样。然后我会像bastien建议的那样优化一切。
  • 达达!感谢大家。我改造了包装盒...jsfiddle.net/nick2ny/G6rYu/18

标签: jquery jquery-ui css firefox transform


【解决方案1】:

它仅适用于 WebKit 浏览器,因为这就是您告诉 CSS 的目标,例如:

-webkit-animation-name: rotate; 
-webkit-animation-duration: 3.0s; 
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;

Firefox 不是使用 WebKit 引擎构建的,因此您需要使用 -moz 前缀来定位它:

/* Target Firefox: */
-moz-animation-name: rotate; 
-moz-animation-duration: 3.0s; 
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;

/* Target Webkit: */
-webkit-animation-name: rotate; 
-webkit-animation-duration: 3.0s; 
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;

/* Target W3C Browsers: */
animation-name: rotate; 
animation-duration: 3.0s; 
animation-iteration-count: infinite;
animation-timing-function: linear;

【讨论】:

  • 他可能没有包含前缀,但是他对一个类应用了两个转换从而抵消了这一事实是否没有问题?
  • 这本身就是另一个问题,但事实上他表示它适用于 Chrome / Safari 而不是 Mozilla...
  • 他使用 Chrome 中的另一种 CSS 方法进行缩放,zoom
  • 我在我的平板电脑上,所以我无法真正检查跨浏览器等,但也许这可以结合前缀并更改转换问题:jsfiddle.net/G6rYu/4
【解决方案2】:

我认为在您的 .elem 元素上使用两次转换存在冲突。动画transform: rotate() 将覆盖transform: scale()。您可以使用包装元素进行缩放并将动画应用到内部元素。

您似乎在 Chrome 中使用 zoom,这可以解释为什么它在该浏览器中有效。

查看这个小提琴:http://jsfiddle.net/G6rYu/5/(适用于 Firefox 和 Chrome)

<div class="wrap">
    <div class="box A">
        <div class="elem A"></div>
    </div>
</div>
<div class="wrap">
    <div class="box B">
        <div class="elem B"></div>
    </div>
</div>

CSS

.wrap {
    width: 175px;
    height: 175px;
    overflow: hidden;
}
.box.A {
    width:175px;
    /* border:1px blue solid; */
}
.box.B {
    position:relative;
    top:0px;
    left:0px;
    float:left;
    height: 175px;
    width:175px;
    /* border:1px blue solid; */
}
.elem {
    width:175px;
    height:175px;
    /* border:1px red solid; */
    background-repeat: no-repeat;
}
.elem.A {
    background-image:url('http://s24.postimg.org/ua9mzwmht/arrow.png');
}
.box.A {
    animation-name: rotate;
    animation-duration: 3.0s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(-360deg);
    }
}
.elem.B {
    background-image:url('http://s29.postimg.org/np8utnv8j/arrow2.png');
}
.box.B {
    animation-name: rotate2;
    animation-duration: 3.0s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}
@keyframes rotate2 {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

【讨论】:

  • 你好 Mathias——我认为你是对的。可悲的是,您的 JSFiddle 没有工作。它说那里没有小提琴。不过感谢您的帮助,我会试一试。
猜你喜欢
  • 1970-01-01
  • 2015-02-10
  • 2021-12-12
  • 1970-01-01
  • 2021-07-04
  • 2017-02-23
  • 1970-01-01
  • 1970-01-01
  • 2013-08-27
相关资源
最近更新 更多