jQuery的scrollTo插件不起作用
我已经研究了几个小时了,但我根本无法弄清楚。
基本上,我有一个很长的项目列表,这些项目会填充到页面下方。当用户单击其中一个项目时,我想将窗口滚动回到将加载内容的最顶部(我知道,这可以说是糟糕的设计,但这是一个单独的问题)。
这是我的脚本的样子:
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
<script type='text/javascript' src='scripts/jquery.jgrowl.js'></script>
<script type='text/javascript' src='scripts/javascript.js'></script>
<script type='text/javascript' src='scripts/supersized.js'></script>
<script type='text/javascript' src='scripts/effects.core.js'></script>
<script type='text/javascript' src='scripts/jquery.scrollTo-1.4.2-min.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js'></script>
这是页面顶部的 HTML:
<div id='header'>
<div id='pagetop'></div>
</div>
这是失败的调用:
$.scrollTo('#pagetop',800)
当我尝试运行此行时,它不会产生错误消息,因此我知道scrollTo 已正确加载,但是当我拨打电话时,它什么也没做。
任何帮助将不胜感激。
I have been at this for hours now and I simply cannot figure it out.
Basically, I have a long list of items that gets populated way down the page. When the user clicks on one of these items, I want to scroll the window back to the very top where the content will be loaded (arguably poor design, I know, but that is a separate issue).
Here are what my scripts look like:
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
<script type='text/javascript' src='scripts/jquery.jgrowl.js'></script>
<script type='text/javascript' src='scripts/javascript.js'></script>
<script type='text/javascript' src='scripts/supersized.js'></script>
<script type='text/javascript' src='scripts/effects.core.js'></script>
<script type='text/javascript' src='scripts/jquery.scrollTo-1.4.2-min.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js'></script>
Here is the HTML of the top of my page:
<div id='header'>
<div id='pagetop'></div>
</div>
And this is the call that fails:
$.scrollTo('#pagetop',800)
It does not produce an error message when I attempt to run this line, so I know scrollTo is being loaded properly, but when I make the call, it simply does nothing.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery 没有
scrollTo
方法。但是您可以使用.scrollTop()
help 在一个物体上。更新
如果您只想让元素滚动到视图中,您可以使用本机 DOM 方法:
甚至
演示: http://www.jsfiddle.net/UHhDT/
更新 2
也可以使用 jQuery
scrollTop
在.animate()
中。例如:
演示:http://www.jsfiddle.net/UHhDT/ 1/
jQuery doesn't have a
scrollTo
method. But you can use.scrollTop()
help on an object.Update
If you just want an element to scroll into view, you can use the native DOM method:
or even
Demo: http://www.jsfiddle.net/UHhDT/
Update 2
jQuerys
scrollTop
can also be used in.animate()
.For instance:
Demo: http://www.jsfiddle.net/UHhDT/1/
您可以使用 .scrollTop()
you can use .scrollTop()