this. $. id only returns undefined

1

I'm using Polymer 2.x, I'm trying to preload the page, I made a div with a load gif and I'm going to get it with setTimeout ... But in the script when I use the function $. load it returns undefined. Could anyone help me put display none in div?

Follow the code

ready(){
   super.ready();
   setTimeout(function(){
     this.$.load.classList.add('hidden'); //Classe adiciona display none
   }, 4000);
}

<div id="load">
   <img src="/* GIF */" alt="Loading..."/>
</div>
    
asked by anonymous 27.08.2018 / 18:34

1 answer

1

I was able to solve, I created a variable to save this, and I used it to add the class. See below

ready(){
    super.ready();
    var element = this
    setTimeout(function(){
      element.$.load.classList.add('hidden');
    }, 4000);
  }
    
27.08.2018 / 19:07