Skip to content

Commit 0efc88b

Browse files
fix: the animator range indicator issue on displaying wrong units (#241)
* added the html and css for the degree display * finished adding degree display element * changed the unit * removed function call duplicates * resolving conflict * fixed issue of restoring to default fixed issue of restoring to default when transitioning to different sections of the animation generator * changed the title display for the animation range inputs * changed the unit for different title Co-authored-by: Dunsin <[email protected]>
1 parent 37812bc commit 0efc88b

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ <h1 id="head">Code Magic</h1>
191191
<label id="degree">
192192
<span class="label-title">
193193
<span>Degree</span>
194-
<span id="degree-display">deg</span>
194+
<span class="unit-display">deg</span>
195+
195196
</span>
196197
<input
197198
type="range"
@@ -248,7 +249,9 @@ <h1 id="head">Code Magic</h1>
248249
<label id="degree">
249250
<span class="label-title">
250251
<span>Degree</span>
251-
<span id="degree-display">deg</span>
252+
253+
<span class="unit-display">deg</span>
254+
252255
</span>
253256
<input
254257
type="range"
@@ -291,7 +294,8 @@ <h1 id="head">Code Magic</h1>
291294
<label id="degree">
292295
<span class="label-title">
293296
<span>Degree</span>
294-
<span id="degree-display">deg</span>
297+
<span class="unit-display">deg</span>
298+
295299
</span>
296300
<input
297301
type="range"
@@ -357,8 +361,9 @@ <h1 id="head">Code Magic</h1>
357361

358362
<label id="degree">
359363
<span class="label-title">
360-
<span>Speed</span>
361-
<span id="degree-display">deg</span>
364+
<span class="title-display">Angle</span>
365+
<span class="unit-display animation">deg</span>
366+
362367
</span>
363368
<input
364369
type="range"

src/main.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ const gradientBackgroundDegree = getRange('gradient-background');
111111
// get all range inputs
112112
const gradientRangeInputs = document.querySelectorAll('.degree-range');
113113

114+
115+
// get title display element for animation
116+
const titleDisplayElement = <HTMLElement>(
117+
document.querySelector('.title-display')
118+
);
119+
114120
menuIcon?.addEventListener('click', () => {
115121
if (navBar?.classList.contains('closed-nav')) {
116122
navBar?.animate(navBarSlideIn, navBarAnimationOptions);
@@ -123,9 +129,11 @@ menuIcon?.addEventListener('click', () => {
123129
}
124130
});
125131

132+
126133
const menu = document.querySelector('.menu') as HTMLElement;
127134
const body = document.querySelector('body') as HTMLElement;
128135

136+
129137
if (getComputedStyle(menu).display == 'block') {
130138
body.onclick = (e) => {
131139
if (e.target !== navBar) {
@@ -307,10 +315,16 @@ closeBar?.addEventListener('click', () => {
307315
const displayGradientValue = (gradientElement: HTMLInputElement) => {
308316
gradientElement.addEventListener('input', (e) => {
309317
const target = e.target as HTMLInputElement;
310-
const degreeDisplayElement = <HTMLElement>(
311-
target.parentElement?.querySelector('#degree-display')
318+
const unitDisplayElement = <HTMLElement>(
319+
target.parentElement?.querySelector('.unit-display')
312320
);
313-
degreeDisplayElement.innerText = `${target.value}deg`;
321+
322+
// change the unit for opacity
323+
const unit = titleDisplayElement.innerText.toLowerCase().includes('opacity')
324+
? ''
325+
: 'deg';
326+
unitDisplayElement.innerText = `${target.value}${unit}`;
327+
314328
});
315329
};
316330

src/pages/animation.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,25 @@ type Values = {
1212
};
1313

1414
const attribute = 'animation';
15-
let getCodeButtonElement = utils.getCopyCodeButton(attribute);
15+
let getCodeButtonElement = utils.getCopyCodeButton(attribute);
16+
17+
const OutputElement = utils.getOutput(attribute);
18+
const DegreeElement = utils.getRange(attribute);
19+
const radio_button_set = utils.getRadioButtonSet(attribute);
20+
21+
initialConfiguration(radio_button_set, DegreeElement, OutputElement);
1622

1723
export function animationGenerator() {
18-
const DegreeElement = utils.getRange(attribute);
1924
const duration = utils.getInputSpinner(attribute);
20-
const radio_button_set = utils.getRadioButtonSet(attribute);
21-
22-
const OutputElement = utils.getOutput(attribute);
2325

2426
const Stylesheet = utils.getStyleSheet();
2527
// getCodeButtonElement = utils.getCopyCodeButton(attribute);
2628
const resultPage = utils.getResultPage();
27-
28-
resultPage.style.display = 'flex';
2929

30-
30+
resultPage.style.display = 'flex';
3131

3232
initial_length = Stylesheet.cssRules.length - 1;
3333

34-
initialConfiguration(radio_button_set, DegreeElement, OutputElement);
35-
3634
if (OutputElement === null) return;
3735

3836
let i = 0;
@@ -58,8 +56,6 @@ getCodeButtonElement.addEventListener('click', () => {
5856
);
5957
});
6058

61-
62-
6359
/**
6460
* sets the animation to the output element
6561
*
@@ -166,6 +162,14 @@ function initialConfiguration(
166162

167163
OutputElement.innerText = 'Lorem Ipsum';
168164

165+
// get the unit display element for animator
166+
const unitDisplayElement = <HTMLElement>(
167+
document.querySelector('.unit-display.animation')
168+
);
169+
const titleDisplayElement = <HTMLElement>(
170+
document.querySelector('.title-display')
171+
);
172+
169173
elements.forEach((el) =>
170174
el.addEventListener('click', () => {
171175
const type = el.value;
@@ -174,11 +178,15 @@ function initialConfiguration(
174178
DegreeElement.max = '90';
175179
DegreeElement.step = '1';
176180
DegreeElement.value = '50';
181+
unitDisplayElement.innerText = `${DegreeElement.value}deg`;
182+
titleDisplayElement.innerText = 'Angle';
177183
} else {
178184
DegreeElement.min = '0';
179185
DegreeElement.max = '1';
180186
DegreeElement.step = '.1';
181187
DegreeElement.value = '.5';
188+
unitDisplayElement.innerText = `${DegreeElement.value}`;
189+
titleDisplayElement.innerText = 'Opacity';
182190
}
183191
})
184192
);

src/style.css

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ textarea {
255255
font-family: inherit;
256256
}
257257

258-
input[type=number]::-webkit-inner-spin-button,
259-
input[type=number]::-webkit-outer-spin-button {
258+
input[type='number']::-webkit-inner-spin-button,
259+
input[type='number']::-webkit-outer-spin-button {
260260
-webkit-appearance: none;
261261
-moz-appearance: none;
262262
appearance: none;
263-
margin: 0;
263+
margin: 0;
264264
}
265265

266266
#degree {
@@ -289,7 +289,7 @@ input[type=number]::-webkit-outer-spin-button {
289289
align-items: center;
290290
}
291291

292-
#degree-display {
292+
.unit-display {
293293
opacity: 0.7;
294294
}
295295

@@ -313,8 +313,9 @@ input[type=number]::-webkit-outer-spin-button {
313313
padding: 4px;
314314
}
315315

316-
.styled-input:focus, .styled-input:focus-visible {
317-
outline:none;
316+
.styled-input:focus,
317+
.styled-input:focus-visible {
318+
outline: none;
318319
}
319320

320321
.styled-input::-webkit-inner-spin-button,

0 commit comments

Comments
 (0)