jQuery scrollTop不滚动 [英] jQuery scrollTop doesn't scroll

查看:332
本文介绍了jQuery scrollTop不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用javascript自动滚动时遇到了麻烦. 我的滚动区域是正文,我的js代码是

I'm having troubles trying scroll automatically with javascript. My scrolling area is the body, my js code is

$("body").animate({scrollTop: $("#myDiv").position().top)

但是我没有任何结果:没有动画,也没有滚动 我也尝试过

but I don't get any result: no animation and no scrolling I also tried

$("body").scrollTop($("#myDiv").position().top);

并替换

$("body") with $(window).

有任何提示吗?

推荐答案

scrollTop是一种jQuery方法,它获取或设置当前元素滚动条的偏移量,但是没有动画.

scrollTop is a jQuery method which gets or sets the the offset of the current elements scroll bar, but with no animation.

您可能会对jQuery插件 scrollTo 感到困惑.你在追.

You might be getting confused with the jQuery plugin scrollTo, which offers the functionality you're after.

您会喜欢使用它;

$(window).scrollTo($('#myDiv');

这篇关于jQuery scrollTop不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆