views:

64

answers:

2

Hi, I wish to create pagination for this image slider I am creating however I have no clue how to go about it. Could anyone help me out?

You can see the slider here:

http://matthewruddy.com/slider

Thanks in advance. Matthew.

A: 

Since you're using a currentimage variable to control the image you're looking at and moving to, you could do it by capturing the number that was clicked and making currentimage = number - 1. Then it would just be a matter of feeding it into an function that's similar to what you're already doing in nextnumber():

$('li.page').click(function(){
    // Get the clicked number
    var currentimage = parseInt($(this).text()) - 1;

    // Paging function similar to nextnumber()
    page(currentimage);
});
Pat
This doesn't seem to work correctly. The numbers don't correspond to the images.. :/
Matthew Ruddy
Ah, my mistake. It's still doable with the number though. I'm assuming you'd have a page size (i.e. 10 images per page). In that case setting `currentimage` would be done as follows: `(number * 10) - 1`.
Pat
+1  A: 

Here's my code & Demo : http://jsbin.com/apawe4

First identify the Index of li(.page) element and animate the element according to Element's Index. following code says what I'm talking about =)

$(document).ready(function(){
   var sliderwidth = 500;
  $('#navigation li').bind('click',function() {
   $('.slider').animate({left:"-" + sliderwidth * $(this).index() },1000);
  });
})
Ninja Dude