KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to make a div animate horizontally back and forth within a certain area. The problem I have right now is that I can't figure out how to make my div move back after it has moved forward. Here is the script that I am using: <script type="text/javascript"> var animatethis = function (targetElement, speed) { $(targetElement).animate( { marginLeft: "+=250px" }, { duration: speed, complete: function () { animatethis(this, speed); animatethis.stop(); $(targetElement).animate({ marginLeft: "-=250px" }); } } ) }; animatethis($('#q1'), 5000); </script>
Tags (comma-separated)
Save Edits
Cancel