Jump to content
Search Community

How to use same selector from previous function!

WarenGonzaga 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

Hey guys please please help to understand THIS on javascript.

 

I am trying to use THIS to select the same selector from parent function.

 

Here's example:

function Animate() {
  console.log("Clicked!");
  TweenMax.to("#thing", 1, {onStart: a});
}

function a() {
  console.log("Yeah!");
  TweenMax.to(this, 1, {y: "100px"});
}

I know this is clever but I want to know how to select the same selector from parent function. Same as THIS.

See the Pen amNXGG by Waren_Gonzaga (@Waren_Gonzaga) on CodePen

Link to comment
Share on other sites

  • Solution

Just do this.

function a() {
  console.log("Yeah!");
  TweenMax.to(this.target, 1, {y: "100px"});
}

If you get confused about THIS, just log it out and you can examine it. If you're trying to use THIS, and it's the window, you're probably have a scope problem.

console.log(this);
  • Like 2
Link to comment
Share on other sites

 

Just do this.

function a() {
  console.log("Yeah!");
  TweenMax.to(this.target, 1, {y: "100px"});
}

If you get confused about THIS, just log it out and you can examine it. If you're trying to use THIS, and it's the window, you're probably have a scope problem.

console.log(this);

Hey buddy you're awesome! Thanks for help it works!

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