jQuery onClick 转到 ID 或类
由于某些奇怪的原因,当我单击 A 标签转到 ID 时,我的标题变得一团糟。那么有没有办法使用 jQuery 来做到这一点,例如 Click()、Goto ID?
<a href="#allreviewstop">Read Reviews (1)</a>
<div style="height:1500px;"> Really Long Stuff</div>
<div id="allreviewstop"> My Reviews go down here</div>
这是我正在处理的页面单击此处
For some odd reason my Header gets all messed up when I click on an A tag to go to an ID. So instead is there a way to use jQuery to do this, such as a Click(), Goto ID?
<a href="#allreviewstop">Read Reviews (1)</a>
<div style="height:1500px;"> Really Long Stuff</div>
<div id="allreviewstop"> My Reviews go down here</div>
This is the page I'm dealing with Click Here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是你所追求的吗?
[编辑]我不记得你是否需要#。如果不行就试试不加。
Is that what you're after?
[edit] I can't remember if you need the # or not. Try it without if it doesn't work.
尝试 jquery ScrollTo 插件 -
还要检查 演示
Try the jquery ScrollTo plugin -
also check the demo
这个插件对您有帮助吗: jQuery ScrollTo ?
Does this plugin helps you: jQuery ScrollTo ?
根据我的经验,
window.location.hash
解决方案只能工作一次。如果您不想使用该插件,您可以尝试以下操作:然后像这样调用它(其中
someID
是您希望滚动到的元素的 ID):通过此您还可以改变动画速度(我将其设置为 0),以便它是即时的,但您可以将值传递给函数,以便代码可重用。
In my experience the
window.location.hash
solution only works once. If you don't want to use the plugin you could try this:and then call it like so (where
someID
is the ID of the element you wish to scroll to):With this you can also vary the animation speed (I have it at 0) so that it is instant, but you could pass the value to the function so the code is reusable.