Share Posted June 13, 2014 Hello, My question with this example : See the Pen umFdy by NicolasJ (@NicolasJ) on CodePen How to ensure that when "Center" is unchecked and click on the button "DO IT 2" the red block is positioned correctly. That is to say that the two upper corners are aligned and the result is displayed [t = 0 | b = 290 | l = 0 | r = 50] and not [55 t = | b = 235 | s = 55 | r = 5] How to ensure that when "Center" is checked and click on the "DO IT 3" button the red block is centered on the gray block? In summary, my question is how to properly calculate the sets of coordinates which I want to go in both cases (centered checked and unchecked) and keeping transformOrigin:"50% 50%". Hoping to be sufficiently clear Thanks Link to comment Share on other sites More sharing options...
Share Posted June 13, 2014 Based on your example, and what I think you're trying to do, I would change the scale on your doIt3, and doIt4 functions to this function doIt3() { init(); centerX = (useCenter ? (containerW - blocW * scale/2) / 2 : 0); centerY = (useCenter ? (containerH - blocH * scale/2) / 2 : 0); TweenLite.to(bloc, 1, {rotation:0, x:centerX, y:centerY, scale:scale, transformOrigin:"50% 50%", onComplete:function() {logResult()}}); } Hopefully that helps you get closer to what you're trying to do. Link to comment Share on other sites More sharing options...
Author Share Posted June 13, 2014 Thanks, I update the pen .. but this solution does not work if you try another scale value, for example 3 Link to comment Share on other sites More sharing options...
Author Share Posted June 13, 2014 Pen updated. I think that the solustion for DoIt3 is centerX = (useCenter ? (containerW - blocW * scale) / 2 -(blocW - blocW*scale)/2: -(blocW - blocW*scale)/2); centerY = (useCenter ? (containerH - blocH * scale) / 2 -(blocH - blocH*scale)/2: -(blocH - blocH*scale)/2); Due to the fact that the scale is from the center of the object Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now