English 中文(简体)
help with onseek and selectors
原标题:

I am using this:

 $(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

            });

        });

(just testing) so that I can parse the current item to my changeimage() function But all I get in my alerts are undefined. WHat do I need to do here to get the current item

问题回答

You can get the current item using the api by calling the following:

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

The getIndex() function gets a numerical position of the element and getItems gets a jquery object with all the items within it. Using the eq() function asks for the item at the given position.

I ve sometimes had bad luck with it, but within the onSeek callback, you should be able to use this variable in place of the windows.api which would look like:

var currentItem = this.getItems().eq(this.getIndex());




相关问题
Get element from selector given an index with jQuery

var items = $(".myClass"); The code above returns a number of items when used to select all elements. How can I select a specific element, for example the second one? Neither items(2) nor items[2] ...

jQuery Selector not working right

Okay, I cannot figure out what I m doing wrong here... Take the following jQuery selector... $( tr[batchid]:has(span.chkselb input:checked) span[id=assetcount] ) This returns 2 elements. Yet if I ...

jQuery select where attribute = value

I am trying to select an input where the value equals a dynamic value trimmed = jQuery.trim(a); preSelectedCheckBox = $(this).find("input[value=" + trimmed + "]"); The element exists but I ...

help with onseek and selectors

I am using this: $(function() { // initialize scrollable window.api = $("div.scrollable").scrollable({ clickable: true, activeClass: "active",...

Object-Oriented jQuery Question

$("#e1").click(function() { $("#descriptions div").removeClass("show"); $("#e1d").addClass("show"); }); $("#e2").click(function() { $("#descriptions div").removeClass("show"); $("#e2d")....

热门标签