[英]Animate scaleX of rotated div
I have a rotated div that is longer than the viewport to cover the screen. 我有一个旋转的div,其长度大于视口以覆盖屏幕。 I used the following code to center the div: 我使用以下代码将div居中:
CSS 的CSS
div {
position: absolute;
left:-25%;
height: 100%;
width: 150%;
transform: rotate(-75deg);
-ms-transform: rotate(-75deg);
-webkit-transform: rotate(-75deg);
background: red;
}
CODE: http://jsfiddle.net/9b8uLgw5/ 代码: http : //jsfiddle.net/9b8uLgw5/
When I try to animate the scaleX of that div using TweenLite, the div is off centered. 当我尝试使用TweenLite为该div的scaleX设置动画时,该div偏离中心。 I have tried using transformOrigin, but is does not seem to work for me. 我曾尝试使用transformOrigin,但似乎对我不起作用。
CODE: http://jsfiddle.net/85s1hrfo/1/ 代码: http : //jsfiddle.net/85s1hrfo/1/
Is this anywhere near your desired outcome? 这在您想要的结果附近吗?
Snippet: 片段:
var myDIV = document.querySelector('div'); TweenLite.set(myDIV, { backgroundColor: 'red', position: 'absolute', left: '50%', top: '50%', width: '150%', height: '100%', xPercent: -50, yPercent: -125, transformOrigin: '100% 100%', rotation: -75 }); TweenLite.fromTo(myDIV, 1, { scaleX: 0 }, { scaleX: 1 });
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script> <div></div>
Hope this helps in some way though. 希望这会有所帮助。
Finally figured it out. 终于想通了。 I had to set the transform-origin
, top
, and right
properties properly. 我必须正确设置transform-origin
, top
和right
属性。
right: 0;
top: -50%;
transform-origin: right center;
Then I calculated the angle from the top right corner of the div to the bottom left in order to get a proper transform angle. 然后,我计算了div右上角到左下角的角度,以获得适当的变换角度。
var tAngle = -1 * Math.atan($('div.container').height()/$('div.container').width())*180/Math.PI)
$('div.bg').css({
'transform': 'rotate(' + tAngle + 'deg)'
})
JS Fiddle with the solution here (scale the result pane and re-run to see the effect: http://jsfiddle.net/85s1hrfo/2/ JS Fiddle此处提供解决方案(缩放结果窗格并重新运行以查看效果: http : //jsfiddle.net/85s1hrfo/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.