我有一个带有滚动插件的简单选项卡脚本,当我单击每个选项卡时,该选项卡的滚动将被激活,但是有一个问题,因为如果您在每个选项卡上单击两次,您的滚动条上会有两个实例页!这是我的代码,有什么想法吗?
PS 我使用 mCustomScrollbar 插件。
(function($){
$(window).load(function(){
$('ul.tabs').each(function(){
var $active, $content, $links = $(this).find('a');
$active = $($links.filter('[href="' + location.hash + '"]')[0] || $links[0]);
$active.addClass('active');
$content = $($active.attr('href'));
$links.not($active).each(function() {
$($(this).attr('href')).hide();
});
// Set scrollbar to main item
$('#mContent').mCustomScrollbar();
// Bind the click event handler
$(this).on('click', 'a', function(e)
{
var $currentScroll = null, $currentTab = $(this).attr('href');
switch ($currentTab)
{
case '#tabs-contentDescription':
$currentScroll = '#mContent';
break;
case '#tabs-contentChangelog':
$currentScroll = '#mChangelog';
break;
case '#tabs-contentPermission':
$currentScroll = '#mPermission';
break;
}
console.log('Current tab is: ' + $currentTab + ' And current scroll div is :' + $currentScroll);
// Make the old tab inactive.
$active.removeClass('active');
$content.hide();
// Update the variables with the new link and content
$active = $(this);
$content = $($(this).attr('href'));
// Make the tab active.
$active.addClass('active');
$content.show();
$($currentScroll).mCustomScrollbar();
e.preventDefault();
});
});
});
}) (jQuery);