Skip to content

Commit bf32811

Browse files
committed
feat: 'angle', 'blur' and 'iteration' options can also be passed as a number
each number will be properly converted to a string with its corresponding unit, before it is passed to 'setCssProperty()'
1 parent 38f7abf commit bf32811

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

js-css-animations/animate.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,16 @@ const updateCssProperties = (element, opts) => {
115115
removeInlineTransition(element);
116116
CUSTOM_CSS_PROPERTIES.forEach(prop => {
117117
if (typeof opts[prop] === 'string' || typeof opts[prop] === 'number') {
118-
if (
119-
['delay', 'duration'].includes(prop) &&
120-
typeof opts[prop] === 'number'
121-
) {
122-
opts[prop] = `${opts[prop]}ms`;
118+
if (typeof opts[prop] === 'number') {
119+
const unit = {
120+
duration: 'ms',
121+
angle: 'deg',
122+
blur: 'px',
123+
iteration: '',
124+
};
125+
unit.delay = unit.duration;
126+
127+
opts[prop] = `${opts[prop]}` + unit[prop];
123128
}
124129
setCssProperty(element, prop, opts[prop]);
125130
}

main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jsCssAnimations.init.collapse({
6666

6767
jsCssAnimations.init.fade({
6868
trigger: '.fade--btn',
69-
blur: '2px',
69+
blur: 12,
7070
keepSpace: true,
7171
});
7272

@@ -97,7 +97,7 @@ jsCssAnimations.init.rotate({
9797
start: () => {
9898
if (validateInput(document.querySelector('#rotation-angle'))) {
9999
// @ts-ignore
100-
const angle = `${document.getElementById('rotation-angle')?.value}deg`;
100+
const angle = Number(document.getElementById('rotation-angle')?.value);
101101
jsCssAnimations.rotate('.rotation-area', { angle: angle });
102102
}
103103
},
@@ -107,7 +107,7 @@ jsCssAnimations.init.rotate({
107107
});
108108

109109
jsCssAnimations.show.fade('#anchor img', {
110-
iteration: 'infinite',
110+
iteration: 10,
111111
duration: '1s',
112112
direction: 'alternate',
113113
});

0 commit comments

Comments
 (0)