Swipe right to toggle class but only if not swiping over specific classes
On my site I toggle classes to show the mobile navigation. Next to the button I offer the possibility swipe right to open the navigation and swipe left to close it again, but i have trouble with my tables.
For big/long tables I am using overflow: auto
which makes those tables scroll able(right & left if the content doesnt fit).
Now if I like to scroll them, the navigation gets open.
I tried something like that:
jQuery:
- $( 'body' ).on('swiperight', 'body:not(.outertable)', function(){
- if($('.nav-toggle').hasClass('is-active')) {
- }else{
- navToggle.addClass('is-active');
- bodymain.addClass('main-nav');
- navContainer.addClass('is-visible');
- html.addClass('nav-open');
- }
- });
- $( 'body' ).on('swipeleft', function(){
- if($('.nav-toggle').hasClass('is-active')) {
- navToggle.removeClass('is-active');
- bodymain.removeClass('main-nav');
- navContainer.removeClass('is-visible');
- html.removeClass('nav-open');
- }
- });
But it's not working.
.outertable is the affected table with overflow:auto.
I know there is a working possibility like that:
- $( 'body' ).on('swipeleft swiperight', '.outertable', function(event) {
- event.stopPropagation();
- event.preventDefault();
- });
But this way im getting a lot of errors and performance issues.
([Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.) 100 of times on a single swipe.
I like to toggle the classes ONLY if i don't swipe right over affected classes.