- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
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 “”)
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);
}
@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);
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);
}
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);
});
}
Ah cool, not sure if you wanted to animate the reset as well :P Yw! You can remove the setTimeout I think.