-2

having issue - is not function error, with my code, here it is:

import $ from 'jquery';
import gsap from 'greensock';

class IntroAnimations{
 constructor(){
    this.ctaEnter         = $('#cta-enter');
    this.loadContent      = $('.center-h-v');
    this.tlLoading        = new TimelineLite();
    this.animationTime    = .5;

    this.ctaEnter.click(function(){
        this.removeLoadContent(); //<- error is here
    })
 }
removeLoadContent(){
    TweenLite.to(this.loadContent, this.animationTime, {autoAlpha: 0})
 }
}

export default IntroAnimations;

Error is when I call this.removeLoadContent(); Can someone help me explain why this is causing an error?

Thank you.

Harp
  • 43
  • 7

2 Answers2

1
this.ctaEnter.click(() => {
    this.removeLoadContent(); //<- error was here
})
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

This is because "this" has different context.

Write your function using the fat arrow and it should works.

removeLoadContent = ()=>{
    TweenLite.to(this.loadContent, this.animationTime, {autoAlpha: 0})
 }
proti
  • 213
  • 3
  • 11