Tezah Zulueta Posted April 15, 2020 Share Posted April 15, 2020 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 More sharing options...
OSUblake Posted April 15, 2020 Share Posted April 15, 2020 "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. 2 Link to comment Share on other sites More sharing options...
Tezah Zulueta Posted April 15, 2020 Author Share Posted April 15, 2020 Hi @OSUblake, Yes click is working but in tablet it needs to click twice before the event trigger Link to comment Share on other sites More sharing options...
OSUblake Posted April 15, 2020 Share Posted April 15, 2020 Clicking once seems to work fine for me here. See the Pen 1e03a0401ea9c76f1501c309c2adcf26 by osublake (@osublake) on CodePen https://cdpn.io/osublake/debug/1e03a0401ea9c76f1501c309c2adcf26 2 Link to comment Share on other sites More sharing options...
ZachSaucier Posted April 15, 2020 Share Posted April 15, 2020 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 More sharing options...
PointC Posted April 15, 2020 Share Posted April 15, 2020 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. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now