BobbyP
BobbyP

Reputation: 2255

removeEventListener for transitionend not working

I have two buttons on the screen. When one is clicked, both slide off the screen by adding css class - which in turn, adds a margin-left css property.

I also have a 'transitionend' eventListener which does some stuff once the transition is complete. My code is

for (const btn of buttons) {

    btn.addEventListener('transitionend', function func(e)
    {
        if (e.propertyName !== 'margin-left') return;

        ... do some stuff ...

        btn.removeEventListener('transitionend', func, false);
    }, false);

    btn.classList.add('slide-out');
}

The addEventListener is working, and the ... do some stuff ... is doing it's thang. But the eventListener is not being removed from either of the buttons.

What am I doing wrong?

Upvotes: 0

Views: 31

Answers (0)

Related Questions