views:

72

answers:

1

I have written a scroller function which will scroll one div inside another one. The idea is to use the setInterval method to change the margin of the inner element to simulate a scrolling div.

The problem I am facing is that the scrolling is not entirely smooth. Sometimes it stops for a split-second and then it resumes. What can I do to remove these random hiccups? (I am moving 1px per 20 milliseconds)

A: 

Use jQuery's .animate() method instead setInterval().

$('div.myclass').animate({
   'scrollLeft':   '+=400'
}, 4000);

as an example.

You can use both, scrollLeft and scrollTop as animate property.

jAndy
What is the difference? I thought JQuery was using setInterval() to implement the animate method.
Niyaz
@Niyaz: Good point, got me. Well, I thought just in case jQuery's animates deals better with it than you probably do.
jAndy