Im working on a banner-slideshow, but working with the navigation i've run into trouble:
function slideSwitch(item) {
if(item) {
//Problem
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
} else {
var $active = $('#banner div.active');
var $activeImage = $("img[src$='/images/active.png']");
if ($active.length == 0) $active = $('#banner div:last');
if ($activeImage.length == 0) $activeImage = $('#banner img:last');
}
}
$("#banner img").click(function () {
slideSwitch($(this));
});
The problem is when clicking on an img in #banner. I want to get the position of the imag开发者_如何学编程e (navigation.indicator) transfered and thereby be able to fade in the selected banner. The problem is here:
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
Im not using index() right since I dont get an object selected.. how to do this?
I've also tried with "$('#banner div')[item]" but this still doesnt return an object..
Using [] on a jQuery object returns the underlying HTML node for that position in the list. What you want is to re-wrap that node in jQuery.
Try "$($('#banner div')[item])"
精彩评论