gilesadamthomas
gilesadamthomas

Reputation: 181

attach bullets to slider images

I have set up a jsfiddle

http://jsfiddle.net/K8aex/

I need the bullets to move the slides also I am trying to attach the click of the bullet to the index of the relevant slide How would I do this? find the index of the bullet the find the index of the img with same index? make that one the current slide?

Any help would be greatly appreciated

   $('.bullets a').click(function(e) {
        e.preventDefault();
        var bulletIndex = (this).index()
        console.log(bulletIndex)
        wrapper.find('li:nth-child(bulletIndex) img').addClass('current');

    });

Thanks

Upvotes: 0

Views: 325

Answers (1)

Constantinius
Constantinius

Reputation: 35059

First of all I'd make abstraction functions to slide to a specific image like, where you set your properties and make your animations:

function slideTo(i) {
    ...
}

You've already implemented it, but it's pretty scattered through your code.

Your provided click handler also has some errors, this is a cleaned up version:

$('.bullets a').click(function(e) {
    e.preventDefault();
    var bulletIndex = $(this).text();
    slideTo(bulletIndex);
});  

Upvotes: 2

Related Questions