I'm very new to jQuery and having some issues figuring out stuff here :)
I want to create a gallery that's something like this.
[IMAGE]
[previous / next]
[ 1 of 5 ] <- (for example, if I have 5 images, I wan开发者_StackOverflow中文版t to display the numbers)
I figured out up to prev / next button part by using jQuery Cycle Plugin, but i couldn't figure out how to display the [1 of 5] part.
Can someone please lend me a hand ? :)
Well, I made this simple example on how you can achieve it, using only jQuery without plugins.
The rotation is a simple line. If you are hitting prev and it is already in the first image, go to the last. If you are hitting next and it is already on the last, go to the first.
if ($this.index() == 0) /* Previous */
{
/* go 1 back or start at the end */
current = ((current - 1) < 0 ? (total - 1) : (current - 1));
}
else /* Next */
{
/* go 1 forward or start at the beginning */
current = ((current + 1) == total ? 0 : (current + 1));
}
Used functions (ref)
- .click
- .css
- .data
- .find
- .index
- .text
- .length
- selectors
精彩评论