【问题标题】:Disable "wrap around" in SlidesJS在 SlidesJS 中禁用“环绕”
【发布时间】:2016-11-19 06:44:29
【问题描述】:

我正在使用SlidesJS,这是一个非常可定制的幻灯片分页插件。

这是我的初始化。

$('.slides').slidesjs
({
    width: 300,
    height: 300,
    navigation: false,             // It's for swiping in an iOS web app
    pagination: false,
    generatePagination: false
});

但是,我不希望幻灯片“反其道而行之”。不知道有没有这个词,所以画了这个图:

绿色 = 下一个
蓝色 = 上一个

我想要的是禁用来自4 -> 11 -> 4 的滑动。我还没有为此找到内置功能或属性。但是,是否有合理的解决方法?

【问题讨论】:

  • 你的意思是一旦幻灯片到达#4,幻灯片就应该被禁用?
  • 向右滑动可以从 4 变为 3,但不能从 4 变为 1。也许“溢出”在这里是正确的术语?
  • 尚未尝试过slidejs,尽管文档为每张幻灯片提供了一个complete 回调,其中number 是动画结束时的幻灯片编号。如果达到#4,您可以禁用或重置幻灯片吗?预期结果是#1 ->#4, #4 -> #3?还是停在#4,停在#1
  • 这个回调可能会起作用,但有些幻灯片只有两页,所以比较数字不会告诉我滑动的方向。
  • 看看jquery.slide.js的第451行,我认为关键就在那里。我刚刚下载了它......所以......不要问我接下来要做什么!大声笑但这看起来像你需要解决的问题:if (next === this.data.total) {next = 0;}

标签: javascript jquery slidesjs


【解决方案1】:

伙计们!我成功了。
花了几个小时。

最初重新创建的问题是here

如下所述,我的工作解决方案是here

我找到了该循环效果的开关。
AND我将其设置为新的option ==> looping (true/false) !!! 如果looping 选项设置为false...它不会循环。

defaults = {
  width: 940,
  height: 528,
  start: 1,
  navigation: {
    active: true,
    effect: "slide"
  },
  pagination: {
    active: true,
    effect: "slide"
  },
  play: {
    active: false,
    effect: "slide",
    interval: 5000,
    auto: false,
    swap: true,
    pauseOnHover: false,
    restartDelay: 2500
  },
  effect: {
    slide: {
      speed: 500
    },
    fade: {
      speed: 300,
      crossfade: true
    }
  },
  callback: {
    loaded: function() {},
    start: function() {},
    complete: function() {}
  },
  looping: false                    // Looping effect from last image to first and vice-versa
};



稍微修改了 Plugin.prototype._slide 函数来实现这一点。
我添加了一个基于 var 的新条件,我称之为 OK_Proceed

这个变量默认是true
尝试转到图像索引 -1data.total 时,其值变为 false...但仅当循环选项设置为 false 时。

我希望保留原来的功能...
;)

var OK_Proceed=true;                                // ADDED var
    console.log( this.options.looping );
    if (next === -1) {
      if( this.options.looping ){
        next = this.data.total - 1;
      }else{
          OK_Proceed=false;
      }
    }
    if (next === this.data.total) {
      if( this.options.looping ){
          next = 0;
      }else{
          OK_Proceed=false;
      }
    }

OK_Proceed 为 false 时:脚本完全绕过动画函数。
它被一个 10 像素的小“反弹”效果所取代。

剩下要做的就是重置data.animating的值:

$.data(_this, "animating", false);

所以这里是完整的功能:

Plugin.prototype._slide = function(number) {            console.log("Line 430 - _slide: ");
  var $element, currentSlide, direction, duration, next, prefix, slidesControl, timing, transform, value,
    _this = this;
  $element = $(this.element);
  this.data = $.data(this);                             console.log( JSON.stringify( $.data(this) ) );
  if (!this.data.animating && number !== this.data.current + 1) {
    $.data(this, "animating", true);
    currentSlide = this.data.current;               console.log("Line 437 - currentSlide: "+currentSlide);
    if (number > -1) {
      number = number - 1;
      value = number > currentSlide ? 1 : -1;               console.log("Line 440 - value: "+value);
      direction = number > currentSlide ? -this.options.width : this.options.width;
      next = number;
    } else {
      value = this.data.direction === "next" ? 1 : -1;
      direction = this.data.direction === "next" ? -this.options.width : this.options.width;
      next = currentSlide + value;                  console.log("Line 446 - next: "+next);
    }   var OK_Proceed=true;                                // ADDED var
    console.log( this.options.looping );
    if (next === -1) {
      if( this.options.looping ){
        next = this.data.total - 1;
      }else{
          OK_Proceed=false;
      }
    }
    if (next === this.data.total) {
      if( this.options.looping ){
          next = 0;
      }else{
          OK_Proceed=false;
      }
    }
    if(OK_Proceed){this._setActive(next);                           // ADDED condition
    slidesControl = $(".slidesjs-control", $element);
    if (number > -1) {
      slidesControl.children(":not(:eq(" + currentSlide + "))").css({
        display: "none",
        left: 0,
        zIndex: 0
      });
    }
    slidesControl.children(":eq(" + next + ")").css({
      display: "block",
      left: value * this.options.width,
      zIndex: 10
    });
    this.options.callback.start(currentSlide + 1);
    if (this.data.vendorPrefix) {
      prefix = this.data.vendorPrefix;
      transform = prefix + "Transform";
      duration = prefix + "TransitionDuration";
      timing = prefix + "TransitionTimingFunction";
      slidesControl[0].style[transform] = "translateX(" + direction + "px)";
      slidesControl[0].style[duration] = this.options.effect.slide.speed + "ms";
      return slidesControl.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", function() {
        slidesControl[0].style[transform] = "";
        slidesControl[0].style[duration] = "";
        slidesControl.children(":eq(" + next + ")").css({
          left: 0
        });
        slidesControl.children(":eq(" + currentSlide + ")").css({
          display: "none",
          left: 0,
          zIndex: 0
        });
        $.data(_this, "current", next);
        $.data(_this, "animating", false);
        slidesControl.unbind("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd");
        slidesControl.children(":not(:eq(" + next + "))").css({
          display: "none",
          left: 0,
          zIndex: 0
        });
        if (_this.data.touch) {
          _this._setuptouch();
        }
        return _this.options.callback.complete(next + 1);
      });
    } else {
      return slidesControl.stop().animate({
        left: direction
      }, this.options.effect.slide.speed, (function() {
        slidesControl.css({
          left: 0
        });
        slidesControl.children(":eq(" + next + ")").css({
          left: 0
        });
        return slidesControl.children(":eq(" + currentSlide + ")").css({
          display: "none",
          left: 0,
          zIndex: 0
        }, $.data(_this, "current", next), $.data(_this, "animating", false), _this.options.callback.complete(next + 1));
      }));
    } } else { 
    console.log("HERE");
    $.data(_this, "animating", false);
    console.log( JSON.stringify( $.data(this) ) );

    // Bouncing effect
    $(".slidesjs-control").stop().animate( { "left" : "-=10px" }, 100, "easeInOutBounce", function(){
        $(".slidesjs-control").animate( { "left" : "+=10px" }, 100, "easeInOutBounce");
    });

     }                      // End added condition
  }
};

我从所有 console.logs 中清除了这段代码并创建了一个zip file ready to use




编辑后的第二天
为了使“触摸”的行为与鼠标单击的链接相同,还有另外两个函数需要修改……上面的 .zip 文件也反映了这些更改……

为点击修改的函数是:_slide.
修改为点击的函数有:_setuptouch_touchmove

您可以修改两个类:bounceForwardbounceBackward

lastest demo is here。在支持触控的设备上试一试。

【讨论】:

  • 这也是我尝试过的。而且它会导致不稳定的行为,所以它不能完全解决它。
  • 我不知道该怎么说。也许 undefined behavior 是正确的技术术语。基本上,显示的是一个空白页面。
  • 另外,与其取消活动并带回页面,我宁愿将其退回,就像“那里什么都没有”一样。就像在 iOS 中通过页面本身实现弹跳一样。
  • 非常接近! :) 你认为你也可以实现弹跳吗?
  • 不管怎样,你给了我一个很好的开始,非常感谢你花在这上面的时间! +1!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 2016-09-15
  • 1970-01-01
  • 2013-12-24
  • 2012-11-04
相关资源
最近更新 更多