Skip to content

Commit c214de8

Browse files
committed
feat: 'transfOrigin' can be passed as an option
to customize transform-origin css property only applicable to collapse/expand and rotation animations
1 parent 354b41c commit c214de8

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

js-css-animations/globals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const PROPERTY_NAMES = Object.freeze({
6060
angle: '--js-css-animation--rotation-angle',
6161
iteration: '--js-css-animation--iteration',
6262
direction: '--js-css-animation--direction',
63+
transfOrigin: '--js-css-animation--transf-origin',
6364
});
6465

6566
/**
@@ -116,7 +117,7 @@ export const CLASS_NAMES = Object.freeze({
116117
'js-anim--rotate-down__ccw',
117118
'js-anim--rotate-left',
118119
'js-anim--rotate-left__ccw',
119-
'js-anim--rotated',
120+
'js-anim--rotate',
120121
'js-anim--rotation-loop',
121122
],
122123
moveBack: [

js-css-animations/js-animations.css

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
to {
77
opacity: 0;
88
transform: scaleY(0);
9-
transform-origin: center top;
9+
transform-origin: var(--js-css-animation--transf-origin);
1010
}
1111
}
1212

1313
@keyframes js-anim--expand {
1414
from {
1515
opacity: 0;
1616
transform: scaleY(0);
17-
transform-origin: center top;
17+
transform-origin: var(--js-css-animation--transf-origin);
1818
}
1919
to {
2020
opacity: 1;
@@ -135,6 +135,7 @@
135135
@keyframes js-anim--rotation-loop {
136136
to {
137137
transform: rotate(var(--js-css-animation--rotation-angle));
138+
transform-origin: var(--js-css-animation--transf-origin);
138139
}
139140
}
140141

@@ -194,8 +195,10 @@
194195
.js-anim--rotate-down__ccw,
195196
.js-anim--rotate-left,
196197
.js-anim--rotate-left__ccw,
197-
.js-anim--rotated {
198+
.js-anim--rotate {
199+
--js-css-animation--transf-origin: 'center';
198200
transform: rotate(var(--js-css-animation--rotation-angle));
201+
transform-origin: var(--js-css-animation--transf-origin);
199202
transition-property: transform;
200203
transition-duration: var(--js-css-animation--duration);
201204
transition-timing-function: var(--js-css-animation--timing-function);
@@ -248,6 +251,8 @@
248251
.js-anim--rotation-loop {
249252
--js-css-animation--rotation-angle: 0deg;
250253
--js-css-animation--iteration: infinite;
254+
--js-css-animation--direction: alternate;
255+
--js-css-animation--transf-origin: 'center';
251256
animation-name: js-anim--rotation-loop;
252257
}
253258

@@ -259,6 +264,11 @@
259264
animation-name: js-anim--fade-in;
260265
}
261266

267+
.js-anim--collapse,
268+
.js-anim--expand {
269+
--js-css-animation--transf-origin: top center;
270+
}
271+
262272
.js-anim--collapse {
263273
animation-name: js-anim--collapse;
264274
}

js-css-animations/js-css-animations.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const toggle = (selector, animA, animB, opts = {}) => {
8787
'angle',
8888
'iteration',
8989
'direction',
90+
'transfOrigin',
9091
'keepSpace',
9192
'overflowHidden',
9293
'dimensionsTransition',
@@ -289,6 +290,22 @@ const jsCssAnimations = (function () {
289290
show: showVisibilityAnim,
290291
hide: hideVisibilityAnim,
291292
toggle: toggle,
293+
blink: (target, opts = {}) => {
294+
jsCssAnimations.show.fade(target, {
295+
duration: '1s',
296+
iteration: 'infinite',
297+
direction: 'alternate',
298+
...opts,
299+
});
300+
},
301+
pulse: (target, opts = {}) => {
302+
jsCssAnimations.show.collapse(target, {
303+
duration: '1s',
304+
iteration: 'infinite',
305+
direction: 'alternate',
306+
...opts,
307+
});
308+
},
292309
isRotated: checkRotation,
293310
/**
294311
* @param {Element|string} selector - Dom element or a valid CSS selector

main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jsCssAnimations.init.collapse({
6262
targetSelector: '.collapse-expand--p__mult',
6363
staggerDelay: 400,
6464
keepSpace: true,
65+
transfOrigin: 'center',
6566
});
6667

6768
jsCssAnimations.init.fade({
@@ -98,16 +99,25 @@ jsCssAnimations.init.rotate({
9899
if (validateInput(document.querySelector('#rotation-angle'))) {
99100
// @ts-ignore
100101
const angle = Number(document.getElementById('rotation-angle')?.value);
101-
jsCssAnimations.rotate('.rotation-area', { angle: angle });
102+
jsCssAnimations.rotate('.rotation-area', {
103+
angle: angle,
104+
});
102105
}
103106
},
104107
complete: () => {
105-
jsCssAnimations.rotate('.rotation-area', { angle: '0deg', delay: '1s' });
108+
jsCssAnimations.rotate('.rotation-area', {
109+
angle: '0deg',
110+
delay: '1s',
111+
});
106112
},
107113
});
108114

109-
jsCssAnimations.show.fade('#anchor img', {
110-
iteration: 10,
115+
jsCssAnimations.pulse('#anchor img', {
116+
transfOrigin: 'bottom',
117+
});
118+
119+
jsCssAnimations.rotationLoop('#anchor2 img', {
120+
angle: 180,
111121
duration: '1s',
112-
direction: 'alternate',
122+
transfOrigin: 'bottom right',
113123
});

0 commit comments

Comments
 (0)