Jump to content
Search Community

Complex Ease as String

DamirG test
Moderator Tag

Go to solution Solved by OSUblake,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

  • Solution

Using eval on a string that is set by the USER is VERY DANGEROUS. Eval is going execute that code like its regular JavaScript code. This means a user can easily change that string to run some type of rogue script, and you're going to end up having a very bad week. 

 

Here's a function to parse your string and return the easing.

TweenMax.to("element", 1, {
  ease: parseEase("SlowMo.ease.config(0.7, 0.7, false)")
});

function parseEase(string) {
  var easing = string.split(".");
  if (easing.length === 2) return window[easing[0]][easing[1]];  
  var cfgExp = /true|false|(-?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig;    
  var config = string.match(cfgExp).map(JSON.parse);
  return window[easing[0]][easing[1]].config.apply(null, config);
}
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...