Jump to content
Search Community

removeEventListener timeline

Romanus test
Moderator Tag

Go to solution Solved by PointC,

Recommended Posts

Hello! I have a timeline. I want tl.play() to work on a computer and not work on a phone.

 

 

The click listener is added like this:

element.addEventListener("click", handler)

 

The click listener is removed like this:

element.removeEventListener("click", handler)

 

 

if you add a listener like this:

element.addEventListener("click", ()=>handler())

then this listener can't be removed (I couldn't)

 

My problem is that tl.play is only added like this:

element.addEventListener("click", ()=>tl.play())

This means I can't remove it. Help me please.

 

See the Pen GRXGbwM?editors=1011 by romanusname (@romanusname) on CodePen

Link to comment
Share on other sites

@PointC Indeed.

 

@Romanus You have to first define the handle function and then use that handler function inside the event listener. Later, you will be able to easily remove that event listener when needed. Check the example. There you can see that for first 2 second you are able to click the square (still have the event listener). But, after 2 seconds event listener is removed.

See the Pen QWVxeYw by demiavaliani (@demiavaliani) on CodePen

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...