Can I use jQuery nth child to receive the button clicked?
I am trying to write my first script (a slideshow).
I would like to have my thumbs clickable to take you to specific slides. Can I use something like nth child to find out which link is being clicked so that I know what slide to move to?
So far I have this:
function changeSlide() {
//Get id of link calling
var clicked = $(this).attr("id");
//Get the 开发者_如何学JAVAcurrent slide and thumb
var currentSlide = $('ul.slideshow li.show');
var currentThumb = $('ul.thumbs li.show');
var nextSlide = $('ul.slideshow').nth-child(clicked);
My idea was that I would then use these variables to animate the current slide/thumb out and fade the next slide/thumb in. As I dont know how many slides/thumbs there would be, I would like to be able to select them by their sibling number, does this make sense?
I know its not much, i know just enough to be dangerous. Any help to keep me going down the right path is appreciated!
======= EDIT ========
I think I may be on to something, would index() be a good match for this?
Here is a link to the script ---> Slideshow
Change
//Add changeSlide call to anchor tags
$('ul.thumbs li a').attr('onClick', 'changeSlide(' + speed + ')');
to
//Add changeSlide call to anchor tags
$('ul.thumbs li a').click(function(){
changeSlide(speed, this);
});
and
function changeSlide(speed) {
//Get id of link calling
var clicked = $(this);
to
function changeSlide(speed, el) {
//Get id of link calling
var clicked = $(el);
精彩评论