Skip to content

Commit 077ac77

Browse files
ctoffaninDun-sin
andauthored
feat: Add a rotation animation in Animator (#267)
* Replace let with const for never reassigned var * Add rotation animation * refactor: remove console.log Co-authored-by: Dunsin <[email protected]>
1 parent 4552147 commit 077ac77

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ <h2>
374374
/>
375375
<span>Flip</span>
376376
</label>
377+
<label id="animation-radio-label" for="rotate">
378+
<input
379+
type="radio"
380+
id="rotate"
381+
name="animation-radio"
382+
value="rotate"
383+
/>
384+
<span>Rotate</span>
385+
</label>
377386
</div>
378387
</div>
379388

src/pages/animation.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Values = {
1212
};
1313

1414
const attribute = 'animation';
15-
let getCodeButtonElement = utils.getCopyCodeButton(attribute);
15+
const getCodeButtonElement = utils.getCopyCodeButton(attribute);
1616

1717
const OutputElement = utils.getOutput(attribute);
1818
const DegreeElement = utils.getRange(attribute);
@@ -137,6 +137,27 @@ function manageAnimation(
137137
OutputElement.style.animation = `turnaround ease-in`;
138138
OutputElement.style.animationDuration = `${values.duration}s`;
139139

140+
// rule_added = true;
141+
} else if (values.type === 'rotate') {
142+
css =
143+
`/*Copy and paste keyframe into your css file, and apply the animation property in the element of your choice*/\n` +
144+
`@keyframes rotate { \n` +
145+
`0% { transform:rotate(0deg); }\n` +
146+
`100% { transform:rotate(${values.degree}deg); }\n` +
147+
`}\n` +
148+
`animate: rotate ${values.duration}s infinite`;
149+
150+
stylesheet.insertRule(
151+
`@keyframes rotate { \n` +
152+
`0% { transform:rotate(0deg); }\n` +
153+
`100% { transform:rotate(${values.degree}deg); }\n` +
154+
`}`,
155+
initial_length + 1
156+
);
157+
158+
OutputElement.style.animation = `rotate ease-in`;
159+
OutputElement.style.animationDuration = `${values.duration}s`;
160+
140161
// rule_added = true;
141162
}
142163
}
@@ -180,6 +201,13 @@ function initialConfiguration(
180201
DegreeElement.value = '50';
181202
unitDisplayElement.innerText = `${DegreeElement.value}deg`;
182203
titleDisplayElement.innerText = 'Angle';
204+
} else if (type === 'rotate') {
205+
DegreeElement.min = '0';
206+
DegreeElement.max = '360';
207+
DegreeElement.step = '1';
208+
DegreeElement.value = '45';
209+
unitDisplayElement.innerText = `${DegreeElement.value}deg`;
210+
titleDisplayElement.innerText = 'Degrees';
183211
} else {
184212
DegreeElement.min = '0';
185213
DegreeElement.max = '1';

0 commit comments

Comments
 (0)