benmajor / jQuery-Touch-Events

A collection of mobile event plugins for jQuery.
MIT License
699 stars 225 forks source link

Works on desktop but not mobile #133

Closed charlottejunker closed 7 years ago

charlottejunker commented 7 years ago

I've tried and failed miserably to get touch working on mobile. This code is great - so much easier to use than jquery mobile or hammer (I am a beginner). So thank you! I've got a gallery working on desktop but I just cannot figure out why, when I push it to my GitHub pages, it will not work (have tried Chrome and Safari on iPhone 6s). Can anyone help? It's so frustrating! Thank you!

Here’s the repository: https://github.com/charlottejunker/charlottejunker.github.io/tree/master/mike_ragan_portfolio Here’s it hosted: http://charlottejunker.github.io/mike_ragan_portfolio/portfolio.html

benmajor commented 7 years ago

I can see that you've included the library within your project, but can't see anywhere inside of gallery.js where you're using the touch events?

charlottejunker commented 7 years ago

Hi Ben! Lines 168-74 - am I supposed to put something else before that to call your library? Thank you so much for getting back to me.

benmajor commented 7 years ago

Hi Charlotte,

It appears that you're cloning elements, which means that the swiping will not work because they do not exist in the DOM when you bind the events. A couple of things to try:

1) Update to the latest release of the lib (https://cdnjs.cloudflare.com/ajax/libs/jquery-touch-events/1.0.9/jquery.mobile-events.min.js)

2) Use event delegation to handle the bindings, e.g.:

$('body').on('swipeleft', '#overlay', function() { next(); }); $('body').on('swiperight', '#overlay', function() { prev(); });

charlottejunker commented 7 years ago

Thanks Ben. I still can't seem to get it to work so I'm going to try to start again with my code and make it happen.