Jump to content
Search Community

IE 11 Error while using [] as parameter for TweenLite in JS

volcanoflash test
Moderator Tag

Go to solution Solved by GreenSock,

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

Hi all!

 

I have some strange error with ie 11 (may be earlier versions too).

 

Here is a simple example of my code:

var gfx_obj = {};
gfx_obj.r1 = 1;
gfx_obj.r2 = 1;
gfx_obj.r3 = 1;
gfx_obj.r4 = 1;

function appearGFX(num)
{
	TweenLite.to(gfx_obj, 1.2, {["r"+ num]:5, ease: Power3.easeOut});
}

appearGFX(1);

So this gives me error in IE only (all other modern browsers is OK).

Screenshot of error is attached.

 

Any thoughts how to fix it?

post-35892-0-60651300-1444931656_thumb.png

See the Pen GpMwVV by anon (@anon) on CodePen

  • Like 1
Link to comment
Share on other sites

  • Solution

I don't think that syntax is valid JavaScript. It seems to work in Chrome, but honestly I've never seen that syntax before in my life. I wouldn't expect it to work directly inside the {}. Maybe try this instead:

function appearGFX(num) {
    var config = {ease:Power3.easeOut};
    config["r" + num] = 5;
    TweenLite.to(gfx_obj, 1.2, config);
}
  • Like 3
Link to comment
Share on other sites

What you are doing is a new feature and won't work in all browsers. Do it just like Jack showed right above my post unless you are using Babel, Traceur, or TypeScript, which will convert the code...

// From this...
TweenLite.to(gfx_obj, 1.2, {["r"+ num]:5, ease: Power3.easeOut});

// Into this...
var _a;

TweenLite.to(gfx_obj, 1.2, (_a = {}, _a["r"+ num] = 5, _a.ease = Power3.easeOut}, _a));
  • Like 2
Link to comment
Share on other sites

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...