Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed May 3, 2024
1 parent 6c9f3af commit a8f9d9b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions p/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
const imgs = document.getElementById("imgs");

let curPid = 0;
let timeout;

// 监听回车键
pid.addEventListener('keypress', function (e) {
Expand Down Expand Up @@ -123,10 +124,6 @@
}

function createImage (id, n) {
if (id !== curPid) {
return;
}

if (!(id > 0)) {
return;
}
Expand Down Expand Up @@ -181,20 +178,29 @@
return;
}

clearTimeout(timeout);

// 设置参数
location.hash = pid.value;
localStorage.setItem('pid', pid.value);
curPid = pid.value - 0;

// 初始化参数
count.innerHTML = 0; // 重置图片数
imgs.innerHTML = ''; // 清空图片
count.innerHTML = "0"; // 重置图片数
imgs.childNodes.forEach(function (img) {
img.src = '';
});

// 显示loading
loading.style.display = 'inline-block';

setTimeout(function () {
createImage(pid.value - 0, 1);
timeout = setTimeout(function () {
const id = pid.value - 0;
if (id !== curPid) {
return;
}
imgs.innerHTML = ''; // 清空图片
createImage(id, 1);
}, 100);
}

Expand Down

0 comments on commit a8f9d9b

Please sign in to comment.