【问题标题】:jSlot - Can we make the first number never land on 0?jSlot - 我们可以让第一个数字永远不会落在 0 上吗?
【发布时间】:2016-02-16 20:44:43
【问题描述】:

我正在使用数字 0-9 使用这个 jquery jSlots (https://github.com/matthewlein/jQuery-jSlots)。有什么办法可以使最终结果在第一个 li 时永远不会落在 0 上?

清晰度:

0129 = 不好

1029 = 好的

【问题讨论】:

标签: jquery random


【解决方案1】:

我已经更新了一些 javascript 代码,现在应该不可能在第一个数字上得到 0,但如果你这样做了,请告诉我:

https://jsfiddle.net/chc7p4xt/7/

更新部分:

1

    // clone lists
    for (var i = base.options.number - 1; i >= 0; i--){
         base.allSlots.push( new base.Slot(i) ); //sends i
    }

2

    // Slot contstructor
    base.Slot = function(i) { //recieves i

        this.spinSpeed = 0;
        this.el = base.$el.clone().appendTo(base.$wrapper)[0];
        this.$el = $(this.el);
        this.loopCount = 0;
        this.number = 0;
        this.count = i; //sets i

    };

3

    if(this.count == 5) //checks if its the first number
    {
        var endNum = base.randomRange( 1, base.liCount - 1 ); //if so, can't be 0
    }
    else
    {
        var endNum = base.randomRange( 1, base.liCount );
    }

编辑:在 cmets 中回答您的问题:

    if(this.count == 5) //checks if its the first number
    {
        var endNum = base.randomRange( 8, base.liCount - 1 ); //Changed the 1 to an 8
    }
    else
    {
        var endNum = base.randomRange( 1, base.liCount );
    }

【讨论】:

  • 没问题,很高兴为您提供帮助:)
  • 快速提问,是否可以将第一个数字设置为仅数字 1 或 2?
猜你喜欢
  • 2014-02-21
  • 2013-01-02
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 2012-01-09
  • 2012-06-20
  • 2013-09-19
  • 2016-12-26
相关资源
最近更新 更多