jquery 选项卡切换链接以便它们跳转到页面顶部?
redsquare 给了我很大的帮助,让我能够从内容中的链接更改 jquery 选项卡,但我还有一个问题正在寻求支持......
当用户单击链接切换到不同的链接时从内容中选项卡,我可以让页面跳转到页面顶部吗?
在我的演示链接中,滚动到页面底部以单击链接,它们会完美地切换选项卡,如果向上滚动,您可以确认这一点。
因此,我正在寻找将用户跳转到页面顶部的开关,这样用户就不必“滚动”到页面顶部来开始阅读新内容。
这是我的演示: http://jsbin.com/etoku3/11
现有代码:
<script type="text/javascript">
$(document).ready(function() {
var $tabs = $("#container-1").tabs();
var changeTab = function(ev){
ev.preventDefault();
var tabIndex = this.hash.charAt(this.hash.length-1) -1;
$tabs.tabs('select', tabIndex);
};
$('a.tablink').click(changeTab);
});
</script>
I was given some great help by redsquare to get this far to change jquery tabs from links within the content, but I have one more issue that I'm looking for support on...
When a user clicks a link to switch to a different tab from within the content, can i get the page to jump to the top of the page?
Within my demo link, scroll to the bottom of the page to click the links and they switch tabs just perfectly, which you can confirm if you scroll up.
So, I'm looking for the switch to also jump the user to the top of the page, so the user doesn't have to "scroll" to the top of the page to begin reading new content.
Here's my demo:
http://jsbin.com/etoku3/11
Existing code:
<script type="text/javascript">
$(document).ready(function() {
var $tabs = $("#container-1").tabs();
var changeTab = function(ev){
ev.preventDefault();
var tabIndex = this.hash.charAt(this.hash.length-1) -1;
$tabs.tabs('select', tabIndex);
};
$('a.tablink').click(changeTab);
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放入
changeTab
函数中:您的代码:
编辑:
如果您想将其设置为动画到顶部,请使用以下代码:
Place this in the
changeTab
function:Your code:
EDIT:
If you want to animate it to the top, use this instead:
window.location = "#";
简单,没有旧浏览器可能不支持的 JavaScript 滚动...
window.location = "#";
Simple, no javascript might-not-be-supported-by-old-browsers scrolling...