我想链接消息标签,一旦用户点击该链接,就应该打开标签并滚动。
滚动功能正常,但如何将标签设置为活动状态?
$('a.js-link-scroll').on('shown.bs.tab', function (e) {
var that = this;
$('html, body').animate({
scrollTop: $( $(that).attr('href') ).offset().top
}, 500);
});
答案 0 :(得分:1)
$('a.js-link-scroll').on('shown.bs.tab', function (e) {
$('#myTabs .active').removeClass('active');//remove all active classes
$('a[href="'+$(this).attr('href')+'"]').parent().addClass('active');//add the active class to the #message tab
var that = this;
$('html, body').animate({
scrollTop: $( $(that).attr('href') ).offset().top
}, 500);
});