Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var requestAnimationFrame = (
- window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- function(fn) { return setTimeout(fn, 1000/60); }
- ),
- animationLoop = function next(fn, immediate) {
- immediate && (fn() === false) || requestAnimationFrame(next.bind(null, fn, true));
- };
- function debounce(fn, threshhold) {
- threshhold = threshhold || 1000/60;
- var timer;
- return function(){
- var run = fn.apply.bind(fn, this, arguments);
- clearTimeout(timer);
- timer = setTimeout(run, threshhold);
- };
- }
- function throttle (fn, threshhold) {
- var next = function(fn) { setTimeout(fn, threshhold); };
- // Wenn threshhold nicht angegeben, mit Bildshirm synchronizieren
- if (!threshhold) {
- threshhold = 1000/60;
- next = window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- next;
- }
- var waiting = false,
- runAfterWait = false,
- run;
- return function() {
- run = fn.apply.bind(fn, this, arguments);
- if (waiting) {
- runAfterWait = true;
- } else {
- run();
- waiting = true;
- next(function() {
- waiting = false;
- if (runAfterWait) {
- runAfterWait = false;
- run();
- }
- });
- }
- };
- }
- function memoize(fn) {
- var cache = {};
- return function() {
- var key = JSON.stringify(arguments);
- if (!cache.hasOwnProperty(key)) {
- cache[key] = fn.apply(this, arguments);
- }
- return cache[key];
- }
- }
Add Comment
Please, Sign In to add comment