
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
A polyfill and wrapper for requestAnimationFrame, providing common functionality for animation and timing loops
#LoopyJS
A polyfill and wrapper for requestAnimationFrame, providing common functionality for animation and timing loops
##Build
Make sure you have grunt-cli installed
$ npm install
$ grunt build
##Usage
Loop some code, and cancel the loop after 1000ms
var animation = loopy(function(deltaTime, timeElapsed){
//deltaTime: time since last loop
//timeElapsed: time since looping started
if(timeElapsed) >= 1000){
animation.cancel();
}
//your loop code here
console.log("Here is another loop!");
});
You can use the this
context
loopy(function(deltaTime, timeElapsed){
if(timeElapsed >= 1000){
this.cancel();
}
});
You can access other less common information with this
context
loopy(function(deltaTime, timeElapsed){
console.log("Currently running frame number: " + this.frame);
});
You can use loopy.request like you would normally use requestAnimationFrame, except the callback time is given as time since the request, instead of currentTime
loopy.request(function(deltaTime){
console.log("It was " + deltaTime + "since we made the request to run this code");
});
You can use built-in animation helpers.
var options = {
initial : 100,
halflife : 1000, //miliseconds
growth: false, //true for growth instead of decay
};
loopy.exponential(function(value, deltaTime, timeElapsed){
console.log("Exponentially decreasing value : " + value);
}, options);
var options = {
amplitude: 100,
phase: 0, //radians
period: 1000, //miliseconds
};
loopy.sinusoidal(function(value, deltaTime, timeElapsed){
console.log("Sinusoidal value : " + value);
}, options);
You should never place code inside an event handler that is listening to the window scroll
event.
This is because the scroll event can be fired a lot more than is needed, slowing down the browser.
Instead, you can use the loopy.scroll(callback);
method
loopy.scroll(function(deltaTime, timeElapsed){
var scrollPosition = window.pageYOffset;
//react to a change in scroll position here...
});
##Contributing
All help is welcome!
Possible future updates include
FAQs
A polyfill and wrapper for requestAnimationFrame, providing common functionality for animation and timing loops
We found that loopyjs 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.