
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
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
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.