3

I am using the .animate method to move a div 100px to the right over 1 second.

So thats 1px every 10ms. Is there an event that would fire after every pixel movement? Or even an event that fires after every 10-20px of movement?

The example above is a simple one, what i will use it for is to track the left: property of multiple elements and work out when to display them only if they are in the visible bounds of the browser.

2 Answers 2

3

the step function in animate is what you need (you have to scroll a bit down for that)

The second version of .animate() provides a step option — a callback function that is fired at each step of the animation. This function is useful for enabling custom animation types or altering the animation as it is occurring. It accepts two arguments (now and fx), and this is set to the DOM element being animated.

$(something).animate({
  ..... settings...
},
{
  {
  step: function(now, fx) {
    // where your code goes
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

Did you even read the API for animate()?

Examples of using step here:

http://www.bennadel.com/blog/1856-Using-jQuery-s-Animate-Step-Callback-Function-To-Create-Custom-Animations.htm

http://james.padolsey.com/javascript/fun-with-jquerys-animate/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.