锚点过渡与标签引导点击功能冲突
Anchor Transition conflicting with Bootstrap click function for Tabs
我试图使用一个引导选项卡单击功能,但我也有麻烦使用动画的锚标签我从stackoverflow得到。似乎点击功能弄乱了标签的点击功能有办法解决这个问题吗?
<div id="tab1">
<ul class="tab1-titles">
<li class="active">
<a href="#1a" data-toggle="tab">Tab1</a>
</li>
<li>
<a href="#2a" data-toggle="tab">Tab2</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1a">
<ul>
<li>list-item-1</li>
<li>list-item-2</li>
</ul>
</div>
<div class="tab-pane active" id="2a">
<ul>
<li>list-item-1</li>
<li>list-item-2</li>
</ul>
</div>
</div>
</div>
Javascript $(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^'//,'') == this.pathname.replace(/^'//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
不添加新的click
事件处理程序,只需使用内置的选项卡更改事件,如下所示
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
var hash = $(e.target).attr("href");
//your code goes here
if (location.pathname.replace(/^'//, '') == this.pathname.replace(/^'//, '') && location.hostname == this.hostname) {
var target = $(hash);
target = target.length ? target : $('[name=' + hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
}
}
});
我有一个同事帮我看了一下,他建议在这个脚本中添加一个类到锚标记。所以我照做了,而且效果很好!我只需要更直接地调用这个函数就可以了。他甚至添加了一个偏移滚动顶,以防你有一个固定的标题到方程式。
$('a[href^="#"].anchortargets:not([href="#"])').click(function() {
if (location.pathname.replace(/^'//,'') == this.pathname.replace(/^'//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: parseInt(target.offset().top) - 140 + 'px'
}, 500);
return false;
}
}
});
相关文章:
- 添加文字和评论功能更新Div
- JavaScript打印功能使日历停止工作
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何防止网页加载后自动启动功能
- 除修剪外的其他功能
- 悬停功能触发器
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 删除CKEditor工具栏按钮,但不删除功能
- 异步facebook功能
- jQuery插件与其他基本的显示/隐藏功能冲突
- 悬停/鼠标悬停功能冲突
- 两个相同的元素需要执行相同的功能,但存在冲突
- 链接单击上的Javascript和Jquery无冲突功能
- 定时功能和用户启动功能之间的冲突
- 由于滚动冲突,JQuery在单击或模糊、停止或终止功能时进行查询
- jQuery表单验证与邮件检查功能冲突
- 锚点过渡与标签引导点击功能冲突
- JavaScript使对象一个全局窗口对象?(无冲突功能)
- jQuery的灯箱功能和砌体/无尽滚动之间的冲突
- Javascript两个窗口.点击功能冲突