我在處理爲什麼我的選項卡內容無法正確切換時遇到一些問題,只能在最後一個工作。有沒有人有任何想法?jQuery自定義選項卡無法正常工作
https://jsfiddle.net/x04o2kb6/
JS:
$(document).ready(function($) {
var activateTab = function(index) {
var tab = $(".tabs-menu li:eq(" + index + ")"),
tabContent = $(".tab div:eq(" + index + ")");
tab.addClass("active");
tab.siblings().removeClass("active");
tabContent.siblings().css("display", "none");
tabContent.show();
}
var automation = {
start: function() {
this.current = setInterval(function() {
var currentIndex = $(".tabs-menu li.active").index(),
max = $(".tabs-menu li.active").parent().children().length;
activateTab(currentIndex + 1 < max ? currentIndex + 1 : 0);
}, 2000);
},
stop: function() {
if (this.current) {
clearInterval(this.current);
}
}
}
$(".tabs-menu a").click(function(event) {
event.preventDefault();
activateTab($(event.currentTarget).parent().index());
});
//automation.start();
});
完美感謝隊友! – James