简体   繁体   English

带有CSS转换的CSS过渡在Chrome中无法正常工作

[英]Css transition with transform rotate not working correctly in Chrome

I have some div elements that i try to move and rotate in perspective. 我有一些div元素,我尝试在透视图中移动和旋转。

fiddle: http://fiddle.jshell.net/nu6EA/ 小提琴: http : //fiddle.jshell.net/nu6EA/

The code works fine in FF 24.0, but have some issues with Chrome 30.0.1599.101. 该代码在FF 24.0中可以正常运行,但Chrome 30.0.1599.101则存在一些问题。 Its interesting that i achieved what i wanted in the transition of the red colored div, but that of the black one is weird. 有趣的是,我在红色div的过渡中实现了我想要的功能,但是黑色div的过渡却很奇怪。 It starts to rotate but it does not in the right direction and not smoothly, but rotates at the end of the transition. 它开始旋转,但方向不正确且不平稳,但在过渡结束时旋转。

Code: 码:

HTML: <div class="left"></div><div class="center"></div> <div id="right"></div> HTML: <div class="left"></div><div class="center"></div> <div id="right"></div>

JS: JS:

 var left = $(".left");

left.toggleClass("block");

left.animate({
    opacity: 1,
    left: "+=200",
    height: "200px",
    top: "0"
}, 4000, function () {
    // Animation complete.
});

var center = $(".center");

center.toggleClass("go-left");
center.animate({
    opacity: 0.3,
    left: "-=200",
    height: "180px",
    top: "10px",
}, 4000, function () {
    // Animation complete.
});

CSS: CSS:

body {
margin: 55px;}
.left {
left: 0;
opacity: 0.3;
position: relative;
float: left;
width: 200px;
height: 180px;
top: 10px;
background-color: red;
outline: 1px solid transparent;
-moz-transform: perspective( 600px ) rotateY( -45deg );
-ms-transform: perspective( 600px ) rotateY( -45deg );
-o-transform: perspective( 600px ) rotateY( -45deg );
-webkit-transform: perspective( 600px ) rotateY( -45deg );
transform: perspective( 600px ) rotateY( -45deg );
-moz-transition: all 5s;
-o-transition: all 5s;
-webkit-transition: all 5s;
transition: all 5s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}

.block {
float: left;
width: 200px;
position: relative;
background-color: red;
outline: 1px solid transparent;
-moz-transform: perspective( 600px ) rotateY( 0deg );
-ms-transform: perspective( 600px ) rotateY( 0deg );
-o-transform: perspective( 600px ) rotateY( 0deg );
-webkit-transform: perspective( 600px ) rotateY( 0deg );
transform: perspective( 600px ) rotateY( 0deg );
}

.go-left {
left: 0;
position: relative;
float: left;
width: 200px;
background-color: black;
outline: 1px solid transparent;
-moz-transform: perspective(600px) rotateY( -45deg );
-ms-transform: perspective( 600px ) rotateY( -45deg );
-o-transform: perspective( 600px ) rotateY( -45deg );
-webkit-transform: perspective( 600px ) rotateY( -45deg );
transform: perspective( 600px ) rotateY( -45deg );
/*-moz-transition: all 5s;
-o-transition: all 5s;
-webkit-transition: all 5s;
transition: all 5s;

-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;*/
}

.center {
position: relative;
height: 200px;
width: 200px;
background-color: black;
float: left;
outline: 1px solid transparent;
-moz-transition: all 3s;
-o-transition: all 3s;
-webkit-transition: all 3s;
transition: all 3s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}

#right {
float: left;
width: 200px;
height: 200px;
background-color: blue;
transform: perspective( 600px ) rotateY( 135deg );
outline: 1px solid transparent;
}

I would like also to know if this is the right way of doing what expected from the fiddle demo. 我也想知道这是否是正确完成小提琴演示所期望的方法。

You don't have to put preserve-3d and perspective everywhere - it only needs to go in the common parent element (body). 您不必在任何地方都保存3D和透视图-它只需要放入公共父元素(正文)中即可。 You also need a common transform origin in the body, so everything is getting the same perspective. 您还需要在身体中使用通用的变换原点,因此所有事物都具有相同的视角。 #right doesn't have a -webkit version of transform. #right没有-webkit版本的transform。 When you fix these problems you get reasonable behavior in Chrome - although you should probably adjust the transform origin. 解决这些问题后,尽管可以调整转换原点,但您在Chrome中会获得合理的行为。

http://fiddle.jshell.net/fcxjM/ http://fiddle.jshell.net/fcxjM/

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

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