简体   繁体   English

如何避免CSS转换(旋转和倾斜原点)向右移动几个像素?

[英]How can I keep my CSS transform (rotate & skew origin) from moving a few pixels to the right?

In the example below, when you click the div, it will rotate and skew, but it looks like the position moves a few pixels to the right during this transition. 在下面的示例中,当您单击div时,它将旋转和倾斜,但是在此过渡期间,该位置看起来像向右移动了几个像素。

Is there a way to force it to stay put on the left side during the transition? 有没有办法强迫它在过渡期间停留在左侧? I have played with origin, but haven't been able to get it just right: 我玩过起源游戏,但一直无法做到正确:

 $('div.book').click(function() { $(this).toggleClass('open'); }); 
 div.bg { background-color: #00adef; display: inline-block } .book { transition: all 2s; width: 145px; height: 200px; background-color: #333; -webkit-origin: left; } .book.open { -webkit-transform: rotateY(-90deg) skewY(-45deg); -webkit-transform-origin: 0 0; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='bg'> <div class='book'> </div> </div> 

You were missing "transform" in -webkit-transform-origin ! 您在-webkit-transform-origin中丢失了“ transform”!

 $('div.book').click(function() { $(this).toggleClass('open'); }); 
 div.bg { background-color: #00adef; display: inline-block } .book { transition: all 2s; width: 145px; height: 200px; background-color: #333; -webkit-transform-origin: left; } .book.open { -webkit-transform: rotateY(-90deg) skewY(-45deg); -webkit-transform-origin: left; transform-origin: left; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='bg'> <div class='book'> </div> </div> 

Change 更改

transition: all 2s;

to: 至:

transition: transform 2s;

since transition: all also transform your origin from (50%, 50%) to (0, 0) transition: all以来transition: all将您的来源也从(50%,50%)转换为(0,0)

 $('div.book').click(function() { $(this).toggleClass('open'); }); 
 div.bg { background-color: #00adef; display: inline-block } .book { /*transition: all 2s;*/ transition: transform 2s; width: 145px; height: 200px; background-color: #333; -webkit-origin: left; } .book.open { -webkit-transform: rotateY(-90deg) skewY(-45deg); -webkit-transform-origin: 0 0; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='bg'> <div class='book'> </div> </div> 

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

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