Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

css transform + css transition = skipped frames [Google Chrome]

When I click on the scene, then box falls down. When I click again, box stands up. Animation is smooth, but when I click many times in different positions, then sometimes animation skips frames.

I have this bug on OS X in Google Chrome. Tested in Opera — everything is ok, there is no bug.

show

http://jsfiddle.net/nw78myhn/1/

Does anybody know how to fix the problem?

<div class="scene">
  <div class="box"></div>
</div>
.scene {
  width: 500px;
  height: 500px;
  position: absolute;
  background: #efefef;
}

.box {
  position: absolute;
  left: 250px;
  top: 100px;
  width: 70px;
  height: 140px;
  background: #000;
  transform: rotate(0deg);
  transform-origin: bottom left;
  transition: transform 600ms linear;
}

.box-transform {
  transform: rotate(-96deg);
}
$('.scene').on('click', function() {
  $('.box').toggleClass('box-transform');
});

UPDATE:

I've noticed that there is no frame skipping if transform-origin is set for .box-transform instead of .box:

http://jsfiddle.net/nw78myhn/2/

But in this case origin is not visually at bottom left. And I don't really understand why.

UPDATE 2 [16 February 2016]: This bug was fixed in newer versions of Google Chrome. Can't reproduce in Chrome 48.0.2564.109

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Seems to be a Chrome bug related to transitioning a single property.

To make your second example suit your needs, you can add a silly transition

$('.scene').on('click', function() {
  $('.box').toggleClass('box-transform');
});
.scene {
  width: 500px;
  height: 500px;
  position: absolute;
  background: #efefef;
}

.box {
  position: absolute;
  left: 250px;
  top: 100px;
  width: 70px;
  height: 140px;
  background: #000;
  transform: rotate(0deg);
  transform-origin: bottom left;
    perspective: 1000px;
    transition-property: transform perspective;
    transition-duration: 600ms;
    transition-timing-function: linear;
    transition-delay: initial;
}

.box-transform {
  transform: rotate(-90deg);
    perspective: 1001px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="scene">
  <div class="box"></div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...