Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Repeat or loop the jquery animation (help)

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45439
    ajnoguerra
    Participant

    Hi, still learning to create simple animation with jquery. This one I’m doing right now is a div that slides to the left of its parent div. But it is only animating ones. What I want to do is to keep it repeating. I tried to research for answers and found that I should put my code inside a function and then call its function name but its not working. Please see this [codepen](http://codepen.io/ajnoguerra/pen/DcCsn “”)

    #138286
    CrocoDillon
    Participant

    You need to reset the width before animating again:

    $(document).ready(function(){
    reslide();
    });
    function reslide(){
    $(‘.slide-right’).css({width:’0′}).animate({width:’100%’}, 400, reslide);
    }

    #138289
    ajnoguerra
    Participant

    @CrocoDillon thanks! Now its working. But I have encountered another problem. How do I make the child div pause for 2sec after showing? I’m using this line but the whole animation stops.

    setTimeout(transition, 2000);

    #138295
    CrocoDillon
    Participant

    Seems like you already figured it out with delay :) This might help if you want to delay resetting width to 0 as well:

    function reslide(){
    $(‘.slide-right’).delay(1000).queue(function(){
    $(this).css({width:’0′}).dequeue();
    }).animate({width:’100%’}, 400, reslide);
    }

    #138296
    ajnoguerra
    Participant

    Finally got what I want to do with a little tweak and help from you @CrocoDillon. Thanks a lot! :)

    $(document).ready(function(){
    reslide();
    });

    function reslide(){
    $(‘.slide-right’).delay(5000).animate({width:’0′}, 600).delay(5000).animate({width:’100%’}, 600, function(){
    setTimeout(reslide, 2000);
    });
    }

    #138297
    CrocoDillon
    Participant

    Ah cool, not sure if you wanted to animate the reset as well :P Yw! You can remove the setTimeout I think.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.