modified: script.js

This commit is contained in:
IrisVega 2024-07-10 15:35:23 +08:00
parent 0205e9cd43
commit 40532b4e7b
1 changed files with 18 additions and 6 deletions

View File

@ -3,7 +3,7 @@ $(document).ready(function() {
$(".tabcontent").hide();
$("#Tab0").show();
$(".tablinks").first().addClass("active");
var openedTabs = new Set();
// 点击选项卡按钮时切换内容
$(".tablinks").click(function() {
var tabName = $(this).data("tab");
@ -41,6 +41,7 @@ $(document).ready(function() {
$(`.tablinks[data-tab="${newTabId}"]`).addClass("active");
bindTabEvents();
updateContentOpacity($("#mySlider").val());
openedTabs.add(newIndex);
});
// 删除选项卡
$(document).on("click", ".closeButton", function() {
@ -122,12 +123,23 @@ $(document).ready(function() {
return parseInt($(this).data("tab").replace("Tab", ""));
}).get();
indices.sort((a, b) => a - b); // 确保索引是按顺序排列的
for (var i = 1; i <= indices.length + 1; i++) {
if (!indices.includes(i)) {
return i;
}
// for (var i = 1; i <= indices.length + 1; i++) {
// if (!indices.includes(i)) {
// return i;
// }
// }
// return indices.length + 1;
//最小索引值
// var maxIndex = indices.length > 0 ? indices[indices.length - 1] : 0; // 找到最大索引值如果没有索引则默认为0
// return maxIndex + 1; // 返回最大索引值加1
//最大索引值
// 找到未打开过的最小索引
var nextIndex = 1;
while (indices.includes(nextIndex) || openedTabs.has(nextIndex)) {
nextIndex++;
}
return indices.length + 1;
return nextIndex;
}
// 初始绑定事件
bindTabEvents();