[英]Bootstrap Tabs - Open particuler tab on a different internal side and jump to anchor by click
Hi all Regarding this post I could solve my problem opening a new page and a particuler tab by using this script 大家好关于此文章,我可以使用此脚本解决打开新页面和“微粒”选项卡的问题
window.onload = function(){
var url = document.location.toString();
if (url.match('#')) {
$('.nav-tabs a[href=#' + url.split('#')[1] + ']').tab('show');
}
//Change hash for page-reload
$('.nav-tabs a[href=#' + url.split('#')[1] + ']').on('shown', function (e) {
window.location.hash = e.target.hash;
});
} }
The link looks like this 链接看起来像这样
index.php?content=seminare#wppp
I'm using a php include function. 我正在使用php include函数。 In this case I include seminare.php into index.php and open tab WPPP.
在这种情况下,我将cademe.php包含到index.php中并打开选项卡WPPP。
The code of the tabs look like this 标签的代码如下所示
<ul class="nav nav-tabs responsive-tabs">
<li class="active">
<a data-toggle="tab" href="#monitor"><i class="fa fa-circle" aria-hidden="true"></i>Monitor</a>
</li>
<li>
<a data-toggle="tab" href="#wppp"><i class="fa fa-circle" aria-hidden="true"></i>WPPP</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="monitor">
content 1
</div><!-- tab-group -->
<div class="tab-pane fade in" id="wppp">
content 2
</div><!-- tab-group -->
</div>
By now I end up on the top of the page without the focus on the open tab. 到现在为止,我最终停留在页面顶部,而没有将焦点放在打开的选项卡上。 So I have to scroll down to the tab.
所以我必须向下滚动到选项卡。 How can I manage to jump to the tab area as well as like the normal anchor functionality?
如何像普通锚点功能一样设法跳到选项卡区域?
Thanks guys. 多谢你们。
I'd use jQuery to do this easily: 我会使用jQuery轻松做到这一点:
$(function() {
$(document).scrollTop( $("#wppp").offset().top );
});
But make sure its visible though. 但是请确保其可见。
Problem solved. 问题解决了。 Because the particuler div was hidden it couldn't work.
由于particuler div被隐藏,因此无法正常工作。
if (url.match('#')) {
$('.nav-tabs a[href=#' + url.split('#')[1] + ']').tab('show');
$('#' + url.split('#')[1]).addClass('active');
}
Add class 'active' and it works 添加类“活动”,它的工作原理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.