0

I have a container with scrollable contents, and I need to move the position of the scroll relatively to its current position, say 20 pixels downwards. I'd like to use ScrollTo plugin, alternatively the scrollTop() jQuery function.

So if I run the desired command again and again, the container scroll is supposed to continue moving until reaching the end. Pseudo-code:

$(myContainer).scrollTo( { delta: '+20px' } );

Gruber
  • 4,478
  • 6
  • 47
  • 74
  • scrollTo seems capable, but its [documentation](http://demos.flesler.com/jquery/scrollTo/) could be better. Best documentation is in the full implementation file. I note that scrollTo does have a way of moving stuff relatively: `$(...).scrollTo( {top:'-=100px', left:'+=100'}, 800 )`. Sorry to say code like this results in no scroll movement in my code. Could be a bug in the plugin, could be something in my code :(. – Gruber May 03 '12 at 13:11

1 Answers1

1

scrollTop should do it:

$('#myContainer').scrollTop($('#myContainer').scrollTop() + delta);

try it on jsfiddle

Felix Ebert
  • 1,103
  • 11
  • 30
  • Thanks, your suggestion works, and thanks for the link to jsfiddle (excellent!). Only problem I've got now is a [jScrollPane bug](http://stackoverflow.com/questions/10445403/jscrollpane-scrollbar-disappears-when-applying-scrollto) that cancels the scroll movement if the scrollbar originated at the top. – Gruber May 09 '12 at 12:08