2014-03-19 35 views
3

我试图在Firefox中使用滑块来“变换:scale(x,x)”css3“动画”。如果我关闭动画,滑块和缩放工作。如果我打开动画,它动画,但缩放不起作用。变换:scale(x,x)在Firefox中的动画不起作用

这是我的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/

+2

你确定你可以使用多个单个元素上变换?当你应用'transform:rotate()'时,它应该只覆盖第一个'transform:scale()'。对于Chrome,您可以使用缩放功能,这样就不会产生冲突。 – Mathias

+0

我认为你可能是对的。我会尝试一下,并使用webkit和no-prefix css3,并使用一个包装,就像你所建议的那样。然后,我会像bastien建议的那样优化所有内容。 – Nick

+0

Ta-DA!感谢大家。我改变了箱子的包装... http://jsfiddle.net/nick2ny/G6rYu/18/ – Nick

回答

1

我觉得这是用你的.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); 
    } 
} 
+0

Howdy Mathias - 我认为你说得对。可悲的是,你的JSFiddle没有工作。它说那里没有小提琴。感谢您的帮助,我会给它一个镜头。 – Nick

+0

不客气。我更新了小提琴链接。 – Mathias

4

它只能在WebKit浏览器,监守那你告诉什么CSS的目标,例如:

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

火狐不与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; 
+0

他可能没有包含前缀,但是在他将两个变换应用于一个类的事实中没有问题哪些因此取消? – Dan

+1

这是另一个问题本身,但事实上,他表示,它在Chrome/Safari中,而不是Mozilla的作品... – BenM

+0

他在Chrome中使用另一种CSS方法来缩放,缩放' – Mathias