I came across the following on github, which forms part of a Class dedicated to managing the behaviour for a drawer-style side navigation.
closeSideNav() {
this.sideNav.classList.remove('side-nav--visible');
this.sideNavContent.classList.add('side-nav__content--animatable');
this.sideNavContent.style.transform = 'translateX(-102%)';
let onSideNavClose = () => {
this.sideNav.removeEventListener('transitionend', onSideNavClose);
}
this.sideNav.addEventListener('transitionend', onSideNavClose);
}
The first three lines of the function need no explanation, but I'm a bit confused by the last three. At first it I thought the transitionend event listener was added and then immediately removed - perhaps signalling to another piece of code not shown here - but now I'm really not used to this pattern.
What's the purpose of these lines?