
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
A small library to run any number of actions on every animation frame, meaning these actions will run as fast as your web browser is capable of running them.
A tiny library (approximately 684 bytes) to run any number of actions on every animation frame, meaning these actions will run as fast as your web browser is capable of running them.
npm install on-paint
or
yarn add on-paint
or
pnpm add on-paint
See an example for details.
An example action called tether is included in the library to give you an idea what's possible. All included example actions can be viewed by inspecting onPaint.fns.
The tether action can be used to keep an element pinned to the same position as a different reference element.
Why include example code in the library? It's the only example I could think of where using this library is the best way to accomplish something, so it's entirely possible that it'll be the only function you ever need or use.
import onPaint from 'on-paint';
const originalElement = document.getElementById('original');
const placeholderElement = document.getElementById('placeholder');
// Use "tether" function
onPaint.set(onPaint.fns.tether({source: originalElement, target: placeholderElement}));
set(action, paused)Sets an action to be run. An action must be a function.
If paused is set to true, then the action will not immediately be run, otherwise an action will be run as soon as it is set, and will continue to run until otherwise specified.
Calling set(action, paused) will return a unique identifier that can be used to selectively pause/resume/delete this particular action.
delete(actionID)Deletes an action from the queue. When called, it must be passed the unique identier that is returned from the set action above.
Automatically pauses the execution of onPaint if there are no longer any active actions.
pause(actionID)Pauses an action, as specified by the unique identifier that is returned from the set action above.
Automatically pauses the execution of onPaint if there are no longer any active actions.
resume(actionID)Resumes an action, as specified by the unique identifier that is returned from the set action above.
run()Runs all the actions.
stop()Stops all the actions from executing, and pauses the execution of onPaint.
clear()Clears all the actions from memory. Automatically pauses the executionof onPaint.
fnsReturns a object of all the example actions included with the onPaint library.
logPerformanceWhen set to true, onPaint will log the performance characteristics of every action as it is run and give an average of how long each action takes to perform.
Wait, so we're running these actions every single frame? Isn't that terrible for overall browser performance?
PROBABLY.
If your actions take too long to run, it's entirely possible that you'll encounter negative effects.
These negative effects can range from:
In other words, use this library at your own risk.
Ideally you should write performant enough actions that all of them are capable of being run in less than 1/60th of a second (or approximately 16ms).
You should also ensure that you either pause or delete every action that you are not actively using so as to avoid any unnecessary performance hits.
Because sometimes ... very, very rarely ... it's actually the best way to accomplish something.
See an example for details.
FAQs
A small library to run any number of actions on every animation frame, meaning these actions will run as fast as your web browser is capable of running them.
We found that on-paint demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.