-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.html
97 lines (83 loc) · 2.76 KB
/
calculator.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<style>
body {
font-size: 24px;
}
h1 {
font-size: 36px;
}
p {
font-size: 20px;
}
.loading-spinner {
border: 8px solid #f3f3f3;
border-top: 8px solid #34db3f;
border-radius: 50%;
width: 150px;
height: 150px;
animation: spin 2s linear infinite;
display: none;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.slow-image {
display: none;
}
</style>
</head>
<body>
<h1>Calculator</h1>
<p>This is a calculator. Please enter two numbers below and click "Calculate".</p>
<div class="loading-spinner"></div>
<input type="text" id="firstNumber" style="font-size: 24px;" placeholder="Enter first number">
<span style="font-size: 24px;"> + </span>
<input type="text" id="secondNumber" style="font-size: 24px;" placeholder="Enter second number">
<button onclick="calculate()" style="font-size: 24px;">Calculate</button>
<canvas class="slow-image" width="640" height="360"></canvas>
<script>
function calculate() {
var firstNumber = document.getElementById("firstNumber").value;
var secondNumber = document.getElementById("secondNumber").value;
var animationDuration = 2000;
document.querySelector('.loading-spinner').style.display = 'inline-block';
setTimeout(function() {
document.querySelector('.loading-spinner').style.display = 'none';
document.querySelector('.slow-image').style.display = 'block';
loadSlowImage();
}, animationDuration);
}
function loadSlowImage() {
var img = new Image();
img.src = "IMG-20240608-WA0093.jpg";
img.onload = function() {
var canvas = document.querySelector('.slow-image');
var ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
var imgWidth = img.width;
var imgHeight = img.height;
var chunkHeight = 1;
var chunks = Math.ceil(imgHeight / chunkHeight);
var currentChunk = 0;
function drawChunk() {
if (currentChunk >= chunks) {
return;
}
var y = currentChunk * chunkHeight;
ctx.drawImage(img, 0, y, imgWidth, chunkHeight, 0, y, imgWidth, chunkHeight);
currentChunk++;
setTimeout(drawChunk, 5);
}
drawChunk();
};
}
</script>
</body>
</html>