Jump to content
Search Community

Multiple Eventlistener

Tezah Zulueta test
Moderator Tag

Recommended Posts

Hi,

 

Is it possible to have two eventlistener to trigger an action in gsap? like click on desktop and touch on mobile or tablet? 

 

I have this code but for some reason it doesn't work. 

 

for (let i = 0; i < clickableDots.length; i++) {
linesNarrowDummy[i].addEventListener("touchstart click", slideAnim);
linesNarrowDummy[i].setAttribute("index", i);
linesNarrowDummy[i].setAttribute("class", dateDots);
clickableDots[i].addEventListener("touchstart click", slideAnim);
clickableDots[i].setAttribute("index", i);
clickableDots[i].setAttribute("class", dateDots);
next[i].addEventListener("touchstart click", slideAnim);
back[i].addEventListener("touchstart click", slideAnim);
}
Link to comment
Share on other sites

"touchstart click" isn't a valid name. That's like jQuery syntax. Only 1 name per event listener.

clickableDots[i].addEventListener("touchstart", slideAnim);
clickableDots[i].addEventListener("click", slideAnim);

 

But I think you just need "click". It should work for touch too.

 

  • Like 2
Link to comment
Share on other sites

3 hours ago, Tezah Zulueta said:

click is working but in tablet it needs to click twice before the event trigger 

There's likely something else going on. Please try to create a minimal demo (like what Blake made above) if you'd like help figuring out what's going wrong. You might even figure it out yourself while you're making the minimal demo! The thread below has more details on how to do so:

 

Link to comment
Share on other sites

6 hours ago, Tezah Zulueta said:

it needs to click twice before the event trigger 

When I see that problem, my first thought is it's a play/reverse on click and the timeline isn't reversed when it's created. Then the first click reverses it, but it seems like nothing happened. Just a guess without a demo.

  • Like 2
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...