简体   繁体   English

带有滑块的 Jquery 二十二十插件

[英]Jquery twenty twenty plugin with slider

Created a twenty twenty before after.创造了一个二十前二十后。 but I want this before after inside the jquery slider.但我想要在 jquery 滑块之前之后。 So that i can view group images of before after这样我就可以查看之前之后的组图像

 $(window).load(function() { $("#container1").twentytwenty(); });
 <link href="http://www.jqueryscript.net/demo/Stylish-jQuery-Images-Comparison-Plugin-twentytwenty/css/twentytwenty.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="http://www.jqueryscript.net/demo/Stylish-jQuery-Images-Comparison-Plugin-twentytwenty/js/jquery.twentytwenty.js"></script> <script src="http://stephband.info/jquery.event.move/js/jquery.event.move.js"></script> <div id="container1"> <img src="http://zurb.com/playground/uploads/upload/upload/29/sample-before.png"> <img src="http://zurb.com/playground/uploads/upload/upload/28/sample-after.png"> </div>

Please help me to create this.请帮我创建这个。

This is actually quite straight forward.这实际上非常简单。 I have put together a working example for you, enjoy:我为您整理了一个工作示例,请享受:

 $(document).ready(function() { //initialize swiper when document ready var mySwiper = new Swiper('.swiper-container', { loop: true, pagination: '.swiper-pagination', nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', onInit: function() { $(".swiper-slide-active .container").twentytwenty(); }, onSlideChangeStart: function() { $('.swiper-slide-active .container').twentytwenty(); }, onlyExternal: true }) });
 <link href="http://www.jqueryscript.net/demo/Stylish-jQuery-Images-Comparison-Plugin-twentytwenty/css/twentytwenty.css" rel="stylesheet" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.0.7/css/swiper.min.css"> <div class="swiper-container"> <div class="swiper-wrapper"> <!-- Slides --> <div class="swiper-slide"> <div class="container"> <img src="http://zurb.com/playground/uploads/upload/upload/29/sample-before.png"> <img src="http://zurb.com/playground/uploads/upload/upload/28/sample-after.png"> </div> </div> <div class="swiper-slide"> <div class="container"> <img src="http://www.catchmyfame.com/jquery/conan_bef_sm.jpg"> <img src="http://www.catchmyfame.com/jquery/conan_aft_sm.jpg"> </div> </div> </div> <!-- If we need pagination --> <div class="swiper-pagination"></div> <!-- If we need navigation buttons --> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.0.7/js/swiper.jquery.min.js"></script> <script src="http://www.jqueryscript.net/demo/Stylish-jQuery-Images-Comparison-Plugin-twentytwenty/js/jquery.twentytwenty.js"></script> <script src="http://stephband.info/jquery.event.move/js/jquery.event.move.js"></script>

Using Swiper Slider I tried to use herrbischoff's method, but was unsuccessful I think due to some outdated swiper data.使用 Swiper Slider 我尝试使用 Herrbischoff 的方法,但我认为由于一些过时的 swiper 数据而失败。 My solution is below and notice a few changes:我的解决方案如下,注意一些变化:

  • touchRatio: 0 is used to turn off dragging so they can actually use the twentytwenty slider. touchRatio: 0用于关闭拖动,因此他们实际上可以使用 2020 滑块。
  • navigation , pagination need to be used as objects navigationpagination需要用作对象
  • on: { ... } followed by subobjects of the event name is the new way to access events. on: { ... }后跟事件名称的子对象是访问事件的新方式。
  • onSlideChangeStart doesn't exist in the new API data, slideChangeTransitionStart does so I believe it was renamed. onSlideChangeStart不存在于新的 API 数据中,而slideChangeTransitionStart确实如此,我相信它已被重命名。

(This is only the script solution, you must add the appropriate html and pull in and js and css to get this to function properly) (这只是脚本解决方案,您必须添加适当的html并拉入和js和css才能使其正常运行)

<script>
    jQuery(document).ready(function () {
    //initialize swiper when document ready  
    var mySwiper = new Swiper('.swiper-container', {
        touchRatio: 0,

        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },

        pagination: {
            el: '.swiper-pagination',
            type: 'bullets',
        },

        on: {
            init: function () {
                jQuery(".swiper-slide-active .swiper-container").twentytwenty();
            },
            slideChangeTransitionStart: function () {
                jQuery('.swiper-slide-active .swiper-container').twentytwenty();
            },
        },
    });
});
</script>

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

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