【问题标题】:help with onseek and selectors帮助 onseek 和 selectors
【发布时间】:2013-05-03 20:42:26
【问题描述】:

我正在使用这个:

 $(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() 函数 但是我收到的所有警报都是未定义的。 我需要在这里做什么才能获得当前项目

【问题讨论】:

    标签: jquery-selectors jquery-scrollable


    【解决方案1】:

    您可以通过调用以下方式使用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());
    

    【讨论】:

    • 谢谢,为我工作。 this 指向 jquery TOOLS 函数中的 api,你可以写得更短:var currentItem = this.getItems().eq(this.getIndex());
    猜你喜欢
    • 2011-06-14
    • 2011-06-03
    • 2011-11-02
    • 2011-06-02
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多