I want a div element to be faded in when a view in polymer 3 is loaded. I try to solve this by adding a css class with opacity: 0 to the div. When the polymer template is ready, the css class should be removed and the css transition should start (to transform opacity to 0 within 2 seconds), but the transition is not executed, the div is only visible when page is loaded.
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import './shared-styles.js';
class MyView1 extends PolymerElement {
static get template() {
return html`
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
.card{
opacity: 1;
transition: 2s opacity;
}
.fade-out {
opacity: 0;
}
</style>
<button on-click="fadeIn">click</button>
<div class="card fade-out" id="myCard">
<div class="circle">1</div>
<h1>View One</h1>
<p>Ut labores minimum atomorum pro. Laudem tibique ut has.</p>
<p>Lorem ipsum dolor sit amet, per in nusquam nominavi periculis, sit elit oportere ea.Lorem ipsum dolor sit amet, per in nusquam nominavi periculis, sit elit oportere ea.Cu mei vide viris gloriatur, at populo eripuit sit.</p>
</div>
`;
}
ready() {
super.ready();
console.log("ready");
this.fadeIn(); //not working
}
fadeIn(){
console.log("fade-in");
this.$.myCard.classList.remove("fade-out");
}
}
window.customElements.define('my-view1', MyView1);