0

我正在使用这个:

 $(function() {

            // initialize scrollable
            window.api = $("div.scrollable").scrollable({
                clickable: true,
                activeClass: "active",
                onSeek: function() {
                    alert("current position is: " + this.getIndex());
                    //remove highlighting from all images
                    $(".items img").removeClass("selected");
                    var position = this.getIndex().toString();
                    var thisItem = $(".items:nth-child(" + position + ")");
                    //var thisItem = allItems(this.getIndex);
                    alert("item is: " + $(this).attr('alt'));
                    changeimage($(".items:nth-child(2)"));
                }
            }).circular().autoscroll({
                interval: 4000,
                api: true,
                autoplay: false,
                steps: 1

            });

        });

(只是测试)以便我可以将当​​前项目解析为我的 changeimage() 函数但是我在警报中得到的所有内容都是未定义的。我需要在这里做什么才能获得当前项目

4

1 回答 1

2

您可以通过调用以下方式使用 api 获取当前项目:

var currentItem = window.api.getItems().eq(window.api.getIndex());

getIndex() 函数获取元素的数字位置,getItems 获取包含其中所有项目的 jquery 对象。使用 eq() 函数在给定位置询问项目。

我有时运气不好,但在 onSeek 回调中,您应该能够使用“this”变量代替 windows.api,如下所示:

var currentItem = this.getItems().eq(this.getIndex());
于 2010-12-09T19:47:43.387 回答