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

我与影子孤独终老i 提交于 2019-12-18 07:00:44

问题


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.

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


回答1:


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>


来源:https://stackoverflow.com/questions/32161553/css-transform-css-transition-skipped-frames-google-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!