Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@foundit/micro-animations
Advanced tools
A framework agnostic light shim over the Web Animation API to swiftly create awaitable micro animations from JS.
A framework agnostic light shim over the Web Animation API to swiftly create awaitable micro animations from JS.
Often times using transitions in the CSS creates constant custom CSS code for every animation, hard to parse and prone to timing problem between CSS timing and JS. By moving the transitions from CSS to JS the result is both cleaner and less code and in perfect sync with other JS events as a result. It is obvious that micro animation belongs in JavaScript and not in CSS. Specially when there is a need to chain events.
The Web Animation API is powerfull but clunky. The microAnimation lib is all you need for your micro animation one liners.
npm install @foundit/micro-animation
import { microAnimation } from '@foundit/micro-animation'
Minimum is to pass an element and a transformEnd object containing the properties you want to animate to.
Animation start state is then picked up from the element's computed style. There is a possibility to set an initial state by transitionInit
argument but unless there is a special reason avoid it to avoid jankiness when the animation is canceled and restarted in quick succession.
async function closeModal() {
await microAnimation({
element: myModalElement,
duration: 300,
transformEnd: { opacity: 0 },
})
removeElement()
}
For a keyframe animation, pass an array of keyframe objects.
The offset property is optional, and defaults to 0. In the example below,
the background color will change to orangered at 70% of the animation.
The keyframes will equally share the duration if the middle keyframe(s) offset
key is omitted.
...
await microAnimation({
element: myAnimatedElement,
duration: 1000,
easing: 'ease-out',
transformEnd: [{
backgroundColor: 'orangered',
opacity: 1, offset: 0.7
}, {
transform: "translateX(0)",
backgroundColor: 'blue'
}]
})
...
microAnimation does not accept a start state, instead it takes the computed styles. In most cases this is desired to avoid jankiness. In case you need to put a start state you'd need to do something similar to:
async function openModal() {
// set start style state
Object.assign(myModalElement.style, {
translate: '0 10px',
opacity: 0,
})
// wait a js cycle to let it render
await new Promise((resolve) => setTimeout(resolve, 0))
// run you micro animation
void microAnimation({
element: myModal,
duration: 300,
easing: 'ease-in',
transformEnd: { opacity: 0 },
})
}
Use void
instead of await
if you don't need to wait for the promise to resolve. Handy if you need to execute it directly inside a useEffect in React where you can't have await. It is also thenable should you prefer that to await.
duration
- duration of the total nimation in mseasing
- any of the easings available in CSS, i.e 'ease-in', 'linear', etcelement
* - a DOM element or ref element if your using Reactfill
- same function as fillMode in CSS, defaults to 'forward'transformEnd
* - a keyframe object or array of keyframe objects containg animatable CSS properties in camel casetransformInit
- Keyframe object with CSS properties to start the animation from. Recommended to omit to use computed style as starting point.A keframe object is an object with camel cased css properties as keys with values.
Links: NPM | Github Issues
Author: nicolas@hervy.se
0.1.1
FAQs
A framework agnostic light shim over the Web Animation API to swiftly create awaitable micro animations from JS.
The npm package @foundit/micro-animations receives a total of 625 weekly downloads. As such, @foundit/micro-animations popularity was classified as not popular.
We found that @foundit/micro-animations demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.