简体   繁体   English

jQuery滑块从最后到第一个过渡

[英]jQuery slider last to first transition

By default, when it's on the last slide the slider just scrolls to the left again to start over, as though it's an infinite loop. 默认情况下,当它在最后一张幻灯片上时,滑块会再次向左滚动以重新开始,就好像是一个无限循环。 I want it to scroll back through all the slides and land on the first one again. 我希望它向后滚动所有幻灯片,然后再次降落在第一张幻灯片上。 Much like it does here (see the end of page: http://store.hogan.com/Hogan/IT/Traditional-20-15/p/HXM2540V600FMOG009 ). 就像这里所做的一样(请参阅页面结尾: http : //store.hogan.com/Hogan/IT/Traditional-20-15/p/HXM2540V600FMOG009 )。 I used "jssor".com javascript to create it, taking carousel demo, and I can't add loop to the options, so I have to create another function but I don't know how to do it. 我使用“ jssor” .com javascript进行了创建,并进行了轮播演示,并且无法在选项中添加循环,因此我必须创建另一个函数,但我不知道该怎么做。

How can that be achieved? 如何实现?

Thank you, I'm new with this stuff. 谢谢,我是新手。

This is my jsfiddle if it can help you, but it doesn't work cause I've some external source that doesn't recognize. 如果可以帮助您,这是我的jsfiddle ,但是它不起作用,因为我有一些无法识别的外部源。 I'm sorry for the length of HTML and CSS codes, I had to take it like that for job. 对于HTML和CSS代码的长度,我感到抱歉,我不得不那样做。

This is my JS. 这是我的JS。

jQuery(document).ready(function Slider($) {

        var numOfCols = 0;
        var slideWidth = 0;

        var bodyWidth = document.body.clientWidth;
        if (bodyWidth) {
            if (bodyWidth >= 770) {
                    numOfCols = 4;
                    slideWidth = 200;
                    console.log("desktop");
                }
                else if (bodyWidth >= 500) {
                    numOfCols = 2;
                    slideWidth = 230;
                    console.log("tablet");
                }
                else {
                    slideWidth = 285;
                    numOfCols = 1;
                    console.log("mobile");
                }
        }

        var jssor_1_options = {
          $AutoPlay: true,
          $AutoPlaySteps: 1,
          $SlideDuration: 500,
          $SlideWidth: slideWidth,
          $SlideSpacing: 3,
          $Cols: numOfCols,
          $PauseOnHover:0,
          $Loop: 2,
          $otpCenter: true
        };

        var jssor_1_slider = new $JssorSlider$("jssor_1", jssor_1_options);


        $("#right").click(function() {
            jssor_1_slider.$Next();
        })

        $("#left").click(function() {
            jssor_1_slider.$Prev();
        });
    });

Please set $Loop: 2 (rewind) 请设置$ Loop:2(快退)

var jssor_1_options = {
  ...
  $Loop: 2,
  ...
};

Please check the Loop option here 请在此处检查“ 循环”选项

Edit 编辑

I checked your code and jsfiddle . 我检查了您的代码和jsfiddle The loop works. 循环有效。 The problem is that the width of 'outer container' and 'slides' container is unexpected. 问题在于“外部容器”和“幻灯片”容器的宽度是意外的。 Please change width of the 2 containers then. 然后,请更改2个容器的宽度。

<div id="jssor_1" data-slide="0" style="position:relative;margin:0 auto;top:0px;left:0px;width:809px;height:350px;overflow:hidden;visibility:hidden;">
<div data-u="slides" style="cursor:default;position:relative;top:0px;left:0px;width:809px;height:350px;overflow:hidden;">

Change width of the 2 container in the following code, 在以下代码中更改2个容器的宽度,

    var bodyWidth = document.body.clientWidth;
    if (bodyWidth) {
        if (bodyWidth >= 770) {
            numOfCols = 4;
            slideWidth = 200;
            console.log("desktop");
        }
        else if (bodyWidth >= 500) {
            numOfCols = 2;
            slideWidth = 230;
            //width of the 2 containers should be 230 x 2 + 3 * 1 = 463
            console.log("tablet");
        }
        else {
            slideWidth = 285;
            numOfCols = 1;
            //width of the 2 containers should be 285
            console.log("mobile");
        }
    }

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

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