-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.css
212 lines (183 loc) · 4.82 KB
/
style.css
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0px;
background-image: url('https://images.rawpixel.com/image_800/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA1L3NrOTc5MS1pbWFnZS1rd3Z1amE5Ni5qcGc.jpg'); /* Add a background image */
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100vh;
padding: 0;
}
form {
max-width: 350px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
position: relative;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="number"] {
width: 90%;
height: 30px;
margin-bottom: 20px;
padding: 10px;
border: 1px solid #ccc;
}
select {
width: 100%;
height: 60px;
margin-bottom: 20px;
padding: 10px;
border: 1px solid #ccc;
}
button[type="button"] {
width: 100%;
height: 30px;
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 10px;
cursor: pointer;
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
transition: bottom 0.3s ease;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2), 2px 4px 0 0 #0f172a ;
transition-duration: 200ms ;
transition: background-color 0.3s ease;
font-weight: bold;
font-size: 18px;
}
button[type="button"]:hover {
background-color: #3e8e41;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.4), 6px 6px 0 0 #0f172a;
transform : translate(-2px, -2px);
}
button[type="button"].enabled {
opacity: 1;
cursor: pointer;
animation: pulse 2s infinite;
}
button[type="button"].enabled:hover {
animation: pulse 1s infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
button[type="button"]:disabled {
opacity: 0.5;
cursor: not-allowed;
animation: none;
}
#result {
font-size: 18px;
font-weight: bold;
margin-top: 20px;
}
#convert-btn {
opacity: 0.5;
cursor: not-allowed;
}
#convert-btn.enabled {
opacity: 1;
cursor: pointer;
}
/* Style for incorrect input */
#convert-btn.wrong-input {
bottom: 10px;
left: calc(50% + 20px * (Math.random() - 0.5)); /* Randomly offset left position */
transform: translateX(-50%);
}
/* Style for no input */
#convert-btn.no-input {
bottom: 10px;
left: calc(50% + 40px * (Math.random() - 0.5)); /* Randomly offset left position */
transform: translateX(-50%);
}
.move {
animation: moveButton 3s linear;
}
@keyframes moveButton {
0% { transform: translateX(0); }
50% { transform: translateX(10px); }
100% { transform: translateX(0); }
}
const tempInput = document.getElementById('temp-input');
const unitSelect = document.getElementById('unit-select');
const convertBtn = document.getElementById('convert-btn');
const resultPara = document.getElementById('result');
// Add event listener for convert button click
convertBtn.addEventListener('click', convertTemperature);
// Add event listener for input field changes to enable/disable button
tempInput.addEventListener('input', () => {
if (tempInput.value !== '') {
convertBtn.classList.add('enabled');
} else {
convertBtn.classList.remove('enabled');
}
});
// Function to convert temperature
function convertTemperature() {
const tempValue = parseFloat(tempInput.value);
const unitValue = unitSelect.value;
// Check if input is a valid number
if (isNaN(tempValue)) {
animateButton();
alert('Please enter a valid temperature value!');
return;
}
let convertedTemp = 0;
let convertedUnit = '';
// Perform conversion based on selected unit
switch (unitValue) {
case 'celsius':
if (tempValue < -273.15) {
alert('Temperature cannot be lower than absolute zero!');
return;
}
convertedTemp = tempValue * 9 / 5 + 32;
convertedUnit = 'Fahrenheit';
break;
case 'fahrenheit':
if (tempValue < -459.67) {
alert('Temperature cannot be lower than absolute zero!');
return;
}
convertedTemp = (tempValue - 32) * 5 / 9;
convertedUnit = 'Celsius';
break;
case 'kelvin':
if (tempValue < 0) {
alert('Temperature cannot be lower than absolute zero!');
return;
}
convertedTemp = tempValue - 273.15;
convertedUnit = 'Celsius';
break;
}
// Display the converted temperature
resultPara.textContent = `The converted temperature is ${convertedTemp.toFixed(2)} ${convertedUnit}`;
}
// Function to animate button
function animateButton() {
convertBtn.classList.add('animate');
setTimeout(() => {
convertBtn.classList.remove('animate');
}, 1000);
}