Trying to make a simple carousel of pictures on jQuery
I can not catch the condition when stopping spinning pictures to the left / right to achieve the end.
var carousel = $ ('. Carousel'). Outerwidth ();
var list_item = $ ('. Carousel Li'). Length;
var list_item_width = $ ('. Carousel Li'). Outerwidth () + 30;
var list_count = (list_item * list_item_width);
$ ('. Next'). Click (Function () {
If ($ ('. Carousel'). position.left & lt; = list_count + 'px') {
$ ('. Next'). show ();
$ ('. Carousel'). Animate ({
Left: '- =' + List_Item_Width
}, 900);
}
ELSE {
$ ('. Next'). Hide ();
RETURN FALSE;
}
still continues to rotate the pictures despite the fact that the limit of
Answer 1, Authority 100%
figured out like))
$ ('. Next'). click (function () {
// Alert (POS);
If (($ ('. Carousel'). position (). Left) & gt; list_count) {
$ ('. Next'). show ();
$ ('. Carousel'). Animate ({
Left: '- =' + List_Item_Width
}, 900);
}
ELSE {
$ ('. Next'). Hide ();
RETURN FALSE;
}
Forgot braces (($. Carousel ‘). position (). Left) & gt; list_count)
Answer 2
And try this:
$ (". Next"). click (function () {
If ($ (". Carousel"). width () & gt; = $ (". Carousel Li"). Last (). position (). Left) {
$ (". Carousel"). Animate ({
ScrollLeft: 0.
}, 200);
} else {
$ (". Carousel"). Animate ({
ScrollLeft: $ (". Carousel"). scrollleft () + list_item_width
}, 200);
}
});
only pre-make the internal container long so that all items can accommodate in it, and external overflof: hidden;