views:

13078

answers:

3

Hi,

I'm trying to scroll down 100px every time the user gets near the top of the document.

I have the function executing when the user gets close to the top of the document, but the .scrollTo function isn't working.

I put an alert after and before to check to see if it actually was the line or not that was stopping it and only the first alert goes off, here's the code:

alert("starting");
$.scrollTo({ top: '+=100px', left: '+=0px' }, 800);
alert("finished");

I know I have the jquery page linked properly because I'm using many other jquery functions throughout and they all work fine. I've also tried removing the 'px' from above and it doesn't seem to make a difference.

+1  A: 

Looks like you've got the syntax slightly wrong... I'm assuming based on your code that you're trying to scroll down 100px in 800ms, if so then this works (using scrollTo 1.4.1):

$.scrollTo('+=100px', 800, { axis:'y' });
Alconja
+8  A: 

If it's not working why don't you try using jQuery's scrollTop method?

$("#id").scrollTop($("#id").scrollTop() + 100);

If you're looking to scroll smoothly you could use basic javascript setTimeout/setInterval function to make it scroll in increments of 1px over a set length of time.

Fermin
+1  A: 

jQuery now supports scrollTop as an animation variable.

$("#id").animate({"scrollTop": $("#id").scrollTop() + 100);

You no longer need to setTimeout/setInterval to scroll smoothly.

Todd
Got some syntax errors - missing your closing {. Otherwise this is a good point.
Josh