### animator.start() Source: http://themadcreator.github.io/gifler/docs.html Starts running the GIF animation loop. ```APIDOC ## animator.start() ### Description Starts running the GIF animation loop. ``` -------------------------------- ### gif.get() Source: http://themadcreator.github.io/gifler/docs.html Returns a promise that will be fulfilled with an Animator instance. The animator will be in an unstarted state, but can be started with a call to animator.animateInCanvas(). ```APIDOC ## gif.get() ### Description To get even more control, and for your convenience, this method returns a promise that will be fulfilled with an **Animator** instance. The animator will be in an unstarted state, but can be started with a call to **animator.animateInCanvas()**. ### Returns - **Promise** - A promise that resolves with an Animator instance. ``` -------------------------------- ### GIF Animation Play/Pause Control Source: http://themadcreator.github.io/gifler Control GIF animation playback using the animator object returned by `.animate()`. The animation can be started and stopped, and the animator handles timing compensation. Click events on the canvas can be used to toggle play/pause. ```javascript gifler('assets/gif/run.gif') .animate('canvas.play-pause') .then(function(animator) { $('canvas.play-pause').click(function(){ if(animator.running()){ animator.stop(); } else { animator.start(); } }); }); ``` -------------------------------- ### gifler() Source: http://themadcreator.github.io/gifler/docs.html The main entry point to the library. Prepares and sends an XHR request to load the GIF file. Returns a Gif instance for interacting with the library. ```APIDOC ## gifler() ### Description This is the main entrypoint to the library. Prepares and sends an XHR request to load the GIF file. Returns a **Gif** instance for interacting with the library. ### Arguments - **url** (string) - URL to .gif file ### Returns - **Gif instance** - An instance object for interacting with the loaded GIF. ``` -------------------------------- ### Load and Animate GIF Source: http://themadcreator.github.io/gifler Use this to load a GIF and animate it directly onto a specified canvas element. Ensure the canvas element exists in your HTML. ```javascript gifler('assets/gif/run.gif').animate('canvas.running-pikachu') ``` -------------------------------- ### animator.animateInCanvas() Source: http://themadcreator.github.io/gifler/docs.html Prepares the canvas to be drawn into and sets up the callbacks for each frame while the animation is running. You can override animator.onDrawFrame() and animator.onFrame() to customize drawing behavior. ```APIDOC ## animator.animateInCanvas() ### Description This method prepares the canvas to be drawn into and sets up the callbacks for each frame while the animation is running. To change how each frame is drawn into the canvas, override **animator.onDrawFrame()** before calling this method. If **animator.onDrawFrame()** is not set, we simply draw the frame directly into the canvas as is. You may also override **animator.onFrame()** before calling this method. onFrame handles the lazy construction of canvas buffers for each frame as well as the disposal method for each frame. ### Arguments - **canvas** (HTMLCanvasElement) - A canvas element. - **setDimensions** (boolean, optional) - If true, the canvas width/height will be set to match the GIF. default: true. ``` -------------------------------- ### gif.frames() Source: http://themadcreator.github.io/gifler/docs.html Runs the animation on the loaded GIF, but passes the canvas context and GIF frame to the onDrawFrame callback for rendering. This gives you complete control of how the frame is drawn into the canvas context. ```APIDOC ## gif.frames() ### Description Runs the animation on the loaded GIF, but passes the canvas context and GIF frame to the **onDrawFrame** callback for rendering. This gives you complete control of how the frame is drawn into the canvas context. ### Arguments - **selector** (string or HTMLCanvasElement) - A element or query selector for a element. - **onDrawFrame** (function) - A callback that will be invoked when each frame should be drawn into the canvas. see Animator.onDrawFrame. - **setDimensions** (boolean, optional) - If true, the canvas's width/height will be set to the dimension of the loaded GIF. default: false. ``` -------------------------------- ### Custom GIF Frame Rendering Source: http://themadcreator.github.io/gifler Implement custom rendering logic for each GIF frame. The callback function receives the canvas context and frame data, allowing manipulation before display. This is useful for effects or compositing. ```javascript var frames = 0; function onDrawFrame(ctx, frame) { // Match width/height to remove distortion ctx.canvas.width = ctx.canvas.offsetWidth; ctx.canvas.height = ctx.canvas.offsetHeight; // Determine how many pikachus will fit on screen var n = Math.floor((ctx.canvas.width)/150) for(var x = 0; x < n; x++) { // Draw a pikachu var left = x * 150; ctx.globalCompositeOperation = 'source-over'; ctx.drawImage(frame.buffer, frame.x + left, frame.y, 150, 100); // Composite a color var hue = (frames * 10 + x * 50) % 360; ctx.globalCompositeOperation = 'source-atop'; ctx.fillStyle = 'hsla(' + hue + ', 100%, 50%, 0.5)'; ctx.fillRect(left, 0, 150, this.height); } frames++; } // Load the GIF, set custom frame render function gifler('assets/gif/run.gif') .frames('canvas.rainbow-pikachus', onDrawFrame); ``` -------------------------------- ### animator.running() Source: http://themadcreator.github.io/gifler/docs.html Returns a boolean indicating whether or not the animation is running. ```APIDOC ## animator.running() ### Description Returns a boolean indicating whether or not the animation is running. ### Returns - **boolean** - True if the animation is running, false otherwise. ``` -------------------------------- ### animator::createBufferCanvas() Source: http://themadcreator.github.io/gifler/docs.html Creates a buffer canvas element since it is much faster to call .putImage() than .putImageData(). The omggif library decodes the pixels into the full gif dimensions. We only need to store the frame dimensions, so we offset the putImageData call. ```APIDOC ## animator::createBufferCanvas() ### Description Creates a buffer canvas element since it is much faster to call **.putImage()** than **.putImageData()**. The omggif library decodes the pixels into the full gif dimensions. We only need to store the frame dimensions, so we offset the putImageData call. ### Arguments - **frame** (object) - A frame of the GIF (from the omggif library) - **width** (number) - width of the GIF (not the frame) - **height** (number) - height of the GIF ### Returns - **HTMLCanvasElement** - A element containing the frame's image. ``` -------------------------------- ### gif.animate() Source: http://themadcreator.github.io/gifler/docs.html Animates the loaded GIF, drawing each frame into the canvas. This matches the look of an tag. ```APIDOC ## gif.animate() ### Description Animates the loaded GIF, drawing each frame into the canvas. This matches the look of an tag. ### Arguments - **selector** (string or HTMLCanvasElement) - A element or query selector for a element. ``` -------------------------------- ### animator.reset() Source: http://themadcreator.github.io/gifler/docs.html Resets the animation loop to the first frame. Does not stop the animation from running. ```APIDOC ## animator.reset() ### Description Resets the animation loop to the first frame. Does not stop the animation from running. ``` -------------------------------- ### animator.stop() Source: http://themadcreator.github.io/gifler/docs.html Stops running the GIF animation loop. ```APIDOC ## animator.stop() ### Description Stops running the GIF animation loop. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.