Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swiperight and swipeleft gestures for slideshow from w3school

I have a problem with jquery swiperight and swipeleft gestures.

I have two slideshows, first one is Bootstrap Carousel and second one is inspiration from w3school.

(codepen)

I found good solution for Bootstrap somewhere on this page. Here is the code. It works perfect.

$(document).ready(function() {
    $(".carousel").swiperight(function() {
        $(this).carousel('prev');
    });
    $(".carousel").swipeleft(function() {
        $(this).carousel('next');
    });
}); 

but if I want this code include and modificate to code from w3school it won't work. So I tried something like this (It won't work in codepen I don't know why..)

$(function(){
            $( ".news-slide-content-img" ).on( "swipeleft", swipeleftHandler );
            $( ".news-slide-content-img" ).on( "swiperight", swiperightHandler );
            function swipeleftHandler( ){
                plusSlides(1).css('display', 'block');
            }
            function swiperightHandler( ){
                plusSlides(-1).css('display', 'none');
            }
        });

If I swipe it it swipe more images than one.

Any ideas how to solve this gesture problem?

Here is codepen

like image 978
liop7410 Avatar asked Nov 08 '22 13:11

liop7410


1 Answers

It is just a matter of jquery version. Using the documentation of the function swipeleft and swiperight, these versions of jquery solve the issue:

src="//code.jquery.com/jquery-3.2.1.min.js"></script>
  <script src="//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js"></script>

However, you also have a typo in the function swipeleftHandler and swipeleftHandler; you can consider these changes:

function swipeleftHandler( ){
    plusSlides(1);
  }
  function swiperightHandler( ){
    plusSlides(-1);
  }

You can have a look at this working snippet : https://codepen.io/edkeveked/pen/ypyJJX

like image 89
edkeveked Avatar answered Nov 15 '22 05:11

edkeveked