简体   繁体   English

来自w3school的幻灯片的Swiperight和swipeleft手势

[英]Swiperight and swipeleft gestures for slideshow from w3school

I have a problem with jquery swiperight and swipeleft gestures. 我有jquery swiperight和swipeleft手势的问题。

I have two slideshows, first one is Bootstrap Carousel and second one is inspiration from w3school . 我有两个幻灯片,第一个是Bootstrap Carousel,第二个是来自w3school的灵感。

(codepen) (codepen)

I found good solution for Bootstrap somewhere on this page. 我在这个页面的某个地方找到了Bootstrap的好解决方案。 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. 但如果我想从w3school代码中包含这个代码包含和modificate代码,它将无法正常工作。 So I tried something like this (It won't work in codepen I don't know why..) 所以我尝试了类似的东西(它不会在codepen中工作,我不知道为什么......)

$(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 这是codepen

It is just a matter of jquery version. 这只是jquery版本的问题。 Using the documentation of the function swipeleft and swiperight , these versions of jquery solve the issue: 使用swipeleftswiperight函数的文档,这些版本的jquery解决了这个问题:

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 ; 但是,你在函数swipeleftHandlerswipeleftHandler也有一个拼写错误; 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 你可以看看这个工作片段: https//codepen.io/edkeveked/pen/ypyJJX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM