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,
st开发者_JS百科eps: 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());
精彩评论