简体   繁体   English

如何将滚动顶部设置为bootstrap3选项卡

[英]How to set scroll top to bootstrap3 tab

http://jsfiddle.net/1fus4o1q/ http://jsfiddle.net/1fus4o1q/

This is my working fiddle. 这是我的工作提琴。 At the end of the home tab "Go to top" link should goes to profile page. 在首页标签的最后,“转到顶部”链接应转到个人资料页面。

My HTML Code is: 我的HTML代码是:

<a href="#profile" role="tab" id="profile-tab" data-toggle="tab" aria-controls="profile" class="go_to_top">Go to Top</a>

Script: 脚本:

   $(' a.go_to_top').click(function (e) {
        e.preventDefault();
        $('a[href="' + $(this).attr('href') + '"]').tab('show');    

    });

If i click the link it goes to the profile tab. 如果我单击链接,它将转到配置文件选项卡。 But it goes to bottom on the section. 但这是本节的最后一部分。 I needs to go to top. 我需要顶一下。 How can I acheive this?? 我该如何实现? Or any other way to reach. 或任何其他方式到达。

something like this ? 这样

$(' a.go_to_top').click(function (e) {
    e.preventDefault();
    var $target = $('a[href="' + $(this).attr('href') + '"]');
    $target.tab('show');
    $('html, body').animate({scrollTop:$target.offset().top})
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM