0

我意识到这个问题相当小众,应该针对github或其他地方的作者。

但是,该插件已经超过 5 年没有更新了,作为一个相对简单的插件,我正在尝试对其进行修改,以防止它在单击Previous或时循环元素Next

有关工作示例,请参见此处:

https://jsfiddle.net/zwb1vr96/2/

如您所见,在Previous按钮打开时按下按钮1会将其变为3.

同样,如果它打开3并且您单击Next,它会循环回到1

正如小提琴中所见,我var listlength = $("#newsticker li").length;在插件函数中给出了一个长度变量 ( ),它告诉我列表中li有多少列表 (或 ) 项目。

下一个修改必须在这些行内:

 if(this.options.nextButton && typeof(this.options.nextButton[0]) !== 'undefined')
                                this.options.nextButton.click(function(e) {
                                        this.moveNext();
                                        this.resetInterval();
                                }.bind(this));
 if(this.options.prevButton && typeof(this.options.prevButton[0]) !== 'undefined')
                                this.options.prevButton.click(function(e) {
                                        this.movePrev();
                                        this.resetInterval();
                                }.bind(this));

但我一直关注这个插件通过定义一个集合height而不修改看不见的li项目来工作的事实。

这是我正在尝试的:

添加一个var count = 0;

next按钮

                            this.options.nextButton.click(function(e) {
                         if (count == 3) { return false; }
                            else { count++; }

以及上一个按钮

  this.options.prevButton.click(function(e) {
                                if (count == 0) { return false; }
                                else { count--; }

它在一定程度上有效——但仍然有问题,并且没有给出正确的计数来返回 false。

JsFiddle 尝试

如何在上面的这些PreviousNext脚本函数中创建一个变量以了解它当前位于哪个列表项(在 jsfiddle 示例中- 12或以及如果正在显示的列表项位于,则阻止触发 Next 按钮(因此阻止上述循环功能)。313

4

2 回答 2

1

您的问题是,自动收报机没有选项可以防止在动画时不断自动删除/附加自动收报机项目:

在此处输入图像描述

你可能会考虑这个替代插件,它有一个autoAppend你可以设置为的选项false,那么我希望自动收报机在没有循环的情况下停止(如果你手动控制它)。

于 2019-07-17T01:50:06.280 回答
0

好吧,我确实找到了一个解决方案——它看起来相当基本,但至少在我有限的例子中它确实起作用:

https://jsfiddle.net/8fcz9470/5/

js函数中的新变量

    var listlength = $("#newsticker li").length;
    var count = 1;

他们修改了Next按钮

 this.options.nextButton.click(function(e) {
                             if (count == 3) {
                             alert(count);
                             return false; 
                             }
                             else if (count < 3) { 
                             count++;
                             alert(count);
                                        this.moveNext();
                                        this.resetInterval();
                             }
                                }.bind(this));

Previous按钮

  this.options.prevButton.click(function(e) {
                                if (count == 1) { alert(count); return false; }
                                else if (count > 0) { 
                                count--; 
                                alert(count);
                                        this.movePrev();
                                        this.resetInterval();
                                        }
                                }.bind(this));

如果有人发现此方法有任何潜在问题,请随时提出更好的答案(就像我说的那样,它看起来确实很基本)!谢谢。

编辑:

实际上,对于动态变量,这似乎在 js 代码中起作用:

    . . . . . 
     Plugin.prototype = {
                    init: function() {
                        var count = 1;
                        var listlength = $("li").length;
     . . . . . 
     . . . . . 
     . . . . . 
     . . . . . 
     if (this.options.nextButton && typeof(this.options.nextButton[0]) !== 'undefined')
    this.options.nextButton.click(function(e) {
        if (count == listlength) {
            return false;
        } else if (count < listlength) {
            count++;
            this.moveNext();
            this.resetInterval();
        }
    }.bind(this));
if (this.options.prevButton && typeof(this.options.prevButton[0]) !== 'undefined')
    this.options.prevButton.click(function(e) {
        if (count == 1) {
            return false;
        } else if (count > 0) {
            count--;
            this.movePrev();
            this.resetInterval();
        }
    }.bind(this));
于 2019-07-17T01:35:27.393 回答