-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowResponse.js
More file actions
32 lines (24 loc) · 1.15 KB
/
Copy pathshowResponse.js
File metadata and controls
32 lines (24 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
document.addEventListener('DOMContentLoaded', function () {
const scrollContent = document.getElementById('scrollContent');
const apiResponse = sessionStorage.getItem('apiResponse');
const autoScroll = sessionStorage.getItem('autoScroll') === 'on';
const scrollTime = parseInt(sessionStorage.getItem('scrollTime'), 10) * 1000 || 20000;
// Insert the API response HTML into the scrollContent div
scrollContent.innerHTML = apiResponse;
if (autoScroll) {
const responseContainer = document.getElementById('responseContainer');
const scrollHeight = scrollContent.scrollHeight;
const clientHeight = responseContainer.clientHeight;
let startTime = null;
function scrollStep(timestamp) {
if (!startTime) startTime = timestamp;
const elapsedTime = timestamp - startTime;
const progress = Math.min(elapsedTime / scrollTime, 1);
responseContainer.scrollTop = progress * (scrollHeight - clientHeight);
if (progress < 1) {
requestAnimationFrame(scrollStep);
}
}
requestAnimationFrame(scrollStep);
}
});