我正在测试标签插件,我想做的一件事就是当用户点击链接(来自外部网站或页面内部)并使用标签的哈希时,浏览器不会跳转到该位置选项卡,而是切换到它。
这是jQuery Tools的标签组件的用法。如果单击下面的链接,则窗口将不会滚动,并显示相关选项卡:
http://flowplayer.org/tools/demos/tabs/anchors.html#first
http://flowplayer.org/tools/demos/tabs/anchors.html#second
http://flowplayer.org/tools/demos/tabs/anchors.html#third
将它与下面的jQuery UI Tabs演示进行比较。打开页面时窗口会滚动:
http://jqueryui.com/demos/tabs/#tabs-1
http://jqueryui.com/demos/tabs/#tabs-2
http://jqueryui.com/demos/tabs/#tabs-3
One of the answers关于SO的类似问题在document.ready handler:
中提出了这个问题setTimeout(function() {
if (location.hash) {
window.scrollTo(0, 0);
}
}, 1);
这可行,但与flowplayer.org相比,滚动非常明显。我想知道flowplayer.org的脚本如何实现这种完美的效果?在查看他们的演示代码后,我找不到任何东西。感谢任何帮助,谢谢!
答案 0 :(得分:2)
当jquery的演示使用具有set id属性的元素时,flowplayer演示似乎在没有任何东西的情况下离开,因此我认为没有“跳跃”。然而,我不能为我的生活做出如何/为什么锚被识别。我怀疑它与jquery本身有什么关系,因为唯一的一行确实是$("ul.tabs").tabs("div.panes > div");
但我可能是错的,其他人可以解释一下。
编辑:错误的jquery在内部使用windows.location.hash
并且确实“使用”了针对href属性。