简体   繁体   English

使用jQuery相对移动可滚动内容

[英]Move scrollable contents relatively with jQuery

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. 我有一个带有可滚动内容的容器,我需要将滚动的位置相对于其当前位置移动,例如向下移动20个像素。 I'd like to use ScrollTo plugin, alternatively the scrollTop() jQuery function. 我想使用ScrollTo插件,或者使用jQuery的scrollTop()

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' } ); $(myContainer).scrollTo({delta:'+ 20px'});

scrollTop should do it: scrollTop应该做到这一点:

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

try it on jsfiddle 在jsfiddle上尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM