Nalex Posted July 26, 2021 Share Posted July 26, 2021 Hey. I started to use gsap animation few weeks ago and create some functions, but i dont know, how i could round values to prevent float values during animations. My code is working, but is very bad code, i think function prettify(num) { let n = num.toString(); return n.replace(/(\d{1,3}(?=(?:\d\d\d)+(?!\d)))/g, "$1" + ' '); } // transform digits like 99000 in digits 99 000 (adding spaces) const total_total = Math.round(((((type * ppl * days * hours) * ak) * tax) + total_cord) / 10) * 10; // my value TweenLite.to(total_result, 0.5, {innerHTML: prettify(total_total), roundProps: 'innerHTML', ease: SteppedEase.config(10), onComplete: function(){ $('#total_result').val(total_total)}}) } // my animation So, to round my values i need now: 1. round value in 10 like (/ 10) * 10) 2. i need to add Stteped ease with config 10 3. i need to add roundProps. Please help me How i can do it easily to prevent float digits during animation. Thank you. Link to comment Share on other sites More sharing options...
Cassie Posted July 26, 2021 Share Posted July 26, 2021 Hey Nalex, could you add a minimal demo or an explanation of what you're trying to achieve? I assume this is a counter of some sort? Link to comment Share on other sites More sharing options...
Nalex Posted July 26, 2021 Author Share Posted July 26, 2021 2 hours ago, Nalex said: loat values during animations. So, it was not very good idea, but i tried to cut the page to make working ranges: Link to comment Share on other sites More sharing options...
Nalex Posted July 26, 2021 Author Share Posted July 26, 2021 1 hour ago, Cassie said: Hey Nalex, could you add a minimal demo or an explanation of what you're trying to achieve? I assume this is a counter of some sort? So, it was not very good idea, but i tried to cut the page to make working ranges: Link to comment Share on other sites More sharing options...
OSUblake Posted July 26, 2021 Share Posted July 26, 2021 You should probably modify the value like this. See the Pen zYwpeaY by GreenSock (@GreenSock) on CodePen Also, you're using GSAP's old syntax. Please check out the Migration Guide. 3 Link to comment Share on other sites More sharing options...
Nalex Posted July 26, 2021 Author Share Posted July 26, 2021 7 minutes ago, OSUblake said: You should probably modify the value like this It looks pretty good. Will try this, thank you! 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