1

I have a website where, using jQuery, on click a sort of slideshow images change. My problem is that when it gets to the end, more colored spaces appear (without images) and I need for it to "loop"; when it gets to 15, go back to one.

This is what I have for the images:

$(document).ready(function() {
    $("body").click(function() {
        $("#con-libros").animate({"left": "-=130px"}, "slow");
    });
});
1

1 Answer 1

0

Try this condition:

$(document).ready(function() {
    $("body").click(function() {
        var current = parseInt($("#con-libros").css('left'))*-1;

        if( current < 0 && current > 1949 ) {
           $("#con-libros").animate({"left": "-=130px"}, "slow");
        }else{
           $("#con-libros").animate({"left": "0px"}, "slow");
        }
    });
});
1
  • thanks, I tred it but somehow didn't work. I tried this though: $(document).ready(function(){ var libro_ancho = 135; var libros_total = 15; var libros = 1; $("body").click(function(){ if (libros == (libros_total-6)) { $("#con-libros").animate({"left": "+="+(libro_ancho*(libros_total-7))+"px"}, "slow"); libros = 1; } else { $("#con-libros").animate({"left": "-="+libro_ancho+"px"}, "slow"); libros += 1; } }) }) and solved it. Thanks anyways!
    – MatiMuala
    Dec 10, 2012 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.