Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Adam Smallman
4,182 PointsJquery Movment timer then reset
Hi guys, I am creating a simple feature for a project The idea is for a div bar to move left every set amount of time. Once it has reached around 15000 I want to div to go back to the start and do it all again.
setInterval(function() {
$( ".bar" ).animate({ "left": "+=13.5em" }, "slow" );
}, 3000);
</script>
This works great, it gets to its position when I need it too it is also very smooth. The Div is moving in time with a slide show.
So when the slide show gets to its last image at around 15000 I want .bar to reset to the start.
I have read that I will need to use a var so that Jquery can remember a position? Although I am not sure how to do that.
Thanks for any help guys,
Hope it all makes sense!
1 Answer
Arthur Verschaeve
20,816 PointsA var in jQuery that can remember a position? Maybe you mean the offset method? https://api.jquery.com/offset/
Adam Smallman
4,182 PointsAdam Smallman
4,182 PointsI saw the solution on a website, I could not make sense of it.
Does anyone know of a way of the above working?
My code above works great, but once it reaches the last word, the bar will continue to move. I need it to stop return to its starting point and do it again. But I can't come up with a working code for this.
Arthur Verschaeve
20,816 PointsArthur Verschaeve
20,816 PointsMaybe you need to post the full code, so we can take a look at it.