Share Posted December 7, 2017 I'm trying to animate a div (mask) from left to right using width, keeping the text static. I have tried to achieve this using transformOrigin & marginLeft Any other suggestions welcome Thanks See the Pen EbzqLQ by friendlygiraffe (@friendlygiraffe) on CodePen Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 Here is similar thread. I am not completely sure but I remember reading @Jonathan's comment recently where he advises to not animate margins as it will cause browser to repaint layout. 4 Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 TweenLite.defaultEase = Power0.easeNone; TweenMax.set(".mask1", {transformOrigin:"100% 50%"}); TweenMax.set(".mask2", {transformOrigin:"0% 50%"}); TweenMax.fromTo(".mask1", 2.2, {width:"0px"}, {width:"300px", ease:Power0.easeNone, repeat:-1, repeatDelay:2}) TweenMax.fromTo(".mask2", 2.2, {width:"300px"}, {width:"0px", ease:Power0.easeNone, repeat:-1, repeatDelay:2}) Having different transform origins and using fromTo gets you the result I think you are looking for? Link to comment Share on other sites More sharing options...
Author Share Posted December 7, 2017 11 minutes ago, Sahil said: Here is similar thread. Thanks Sahil, I couldn't see a solution on that thread that kept the contents (text) static Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 Hi, And here a proper made to measure ... See the Pen a83f0373bb538d1745958cfafae88ceb by mikeK (@mikeK) on CodePen It could be easy. Happy learning ... Mikel 1 Link to comment Share on other sites More sharing options...
Author Share Posted December 7, 2017 Just now, mikel said: Hi, And here a proper made to measure ... See the Pen a83f0373bb538d1745958cfafae88ceb by mikeK (@mikeK) on CodePen It could be easy. Happy learning ... Mikel Thanks Mikel, nearly - I need the text be static Here's a better example of what I mean. Have a look at the red version for what I'm trying to achieve (without having to animated the text): See the Pen OOeLxW by friendlygiraffe (@friendlygiraffe) on CodePen Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 Hi, like this one See the Pen f1a1eb5ab36b4965f2d23fcc5ce77189 by mikeK (@mikeK) on CodePen Best regards Mikel 3 Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 @friendlygiraffe whenever you are animating any element, make sure to set it's position. Otherwise you will see a lot of unexpected behavior. @craftedbygc When you are animating width, transform origin doesn't really matter. It is only taken in consideration when you are doing any transforms like scaling, animating skewX/skewY etc. See the Pen OOeLaj by Sahil89 (@Sahil89) on CodePen 5 Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 I haven't looked at all the examples in depth but setting right:0 on the element will make it grow from the right when you increase its width. .mask2 { position:absolute; right:0; } See the Pen MOMawx?editors=1010 by GreenSock (@GreenSock) on CodePen The trick is just putting it in the proper place to begin with. 3 Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 @Carl he wants the text to be static, more like clipping effect. I didn't read it on first response either. Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 @sahil, thanks for the clarification. I didn't get that from his first post and demo. makes sense. 1 Link to comment Share on other sites More sharing options...
Share Posted December 7, 2017 Hello @friendlygiraffe, why not just use an SVG clip-path or SVG mask? Examples of animating the SVG <mask> element using the GSAP AttrPlugin: See the Pen EbBKOz by jonathan (@jonathan) on CodePen You want to stay away from animating left, margin-left or width since they trigger layout like @Sahil advised above. which means the browser has to calculate the layout on each render tick, which equals bad janky (lost frames) jitter bug https://csstriggers.com/width https://csstriggers.com/left https://csstriggers.com/margin-left Happy Tweening! 4 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