Welcome
Beautiful animated mesh gradient background
### Import and Initialize Gradient Source: https://github.com/jordienr/whatamesh/blob/master/README.md Import the Gradient class and initialize it with the ID of your canvas element. This is the basic setup for creating a gradient. ```javascript import { Gradient } from "whatamesh"; const gradient = new Gradient(); gradient.initGradient("#gradient-canvas"); ``` -------------------------------- ### initGradient Method Source: https://context7.com/jordienr/whatamesh/llms.txt Explains how to use the `initGradient` method to initialize the animated gradient on a specified canvas element, including HTML and CSS setup. ```APIDOC ## initGradient(selector) ### Description Initializes the gradient animation on the specified canvas element. This is the primary method to start the gradient effect. It reads CSS custom properties for colors and sets up the WebGL context. ### Method `initGradient(selector: string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Endpoint This method is called on a `Gradient` instance. ### Request Example ```html ``` ### Response This method does not return a value. It initializes the gradient on the canvas. ``` -------------------------------- ### HTML Canvas and CSS for Gradient Setup Source: https://context7.com/jordienr/whatamesh/llms.txt Define a canvas element in HTML and set its dimensions and gradient colors using CSS custom properties. Then, initialize the gradient using JavaScript. ```html ``` -------------------------------- ### Gradient Class Initialization and Control Source: https://context7.com/jordienr/whatamesh/llms.txt Demonstrates how to import the Gradient class, initialize it on a canvas element, and control animation playback and color toggling. ```APIDOC ## Gradient Class Usage ### Description This section details the usage of the `Gradient` class from the Whatamesh library, including initialization, animation control, and color manipulation. ### Method `import { Gradient } from "whatamesh";` ### Initialization ```javascript const gradient = new Gradient(); gradient.initGradient("#gradient-canvas"); ``` ### Animation Control ```javascript gradient.pause(); // Pause the animation gradient.play(); // Resume the animation ``` ### Color Toggling ```javascript gradient.toggleColor(0); // Toggle first color layer (index 0-3) gradient.toggleColor(2); // Toggle third color layer (index 0-3) ``` ### Legend Control ```javascript gradient.showGradientLegend(); gradient.hideGradientLegend(); ``` ``` -------------------------------- ### play() and pause() Methods Source: https://context7.com/jordienr/whatamesh/llms.txt Details the `play()` and `pause()` methods for controlling the animation playback dynamically without destroying the WebGL context. ```APIDOC ## play() and pause() ### Description Control methods for starting and stopping the gradient animation without destroying the WebGL context. `pause()` stops the animation frame loop, and `play()` resumes it. ### Method `play(): void` `pause(): void` ### Parameters None ### Endpoint These methods are called on a `Gradient` instance. ### Request Example ```javascript import { Gradient } from "whatamesh"; const gradient = new Gradient(); gradient.initGradient("#gradient-canvas"); // Example: Toggle button functionality const toggleButton = document.getElementById("toggle-btn"); let isPlaying = true; toggleButton.addEventListener("click", () => { if (isPlaying) { gradient.pause(); toggleButton.textContent = "Play"; } else { gradient.play(); toggleButton.textContent = "Pause"; } isPlaying = !isPlaying; }); // Example: Pause when element is not visible for performance const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { gradient.play(); } else { gradient.pause(); } }); }); observer.observe(document.getElementById("gradient-canvas")); ``` ### Response These methods do not return a value. They control the animation state. ``` -------------------------------- ### Initialize and Control Gradient Animation Source: https://context7.com/jordienr/whatamesh/llms.txt Import the Gradient class and use its methods to initialize, play, pause, and toggle colors on a canvas element. Ensure the canvas element exists and CSS custom properties are defined. ```javascript import { Gradient } from "whatamesh"; // Create a new Gradient instance const gradient = new Gradient(); // Initialize the gradient on a canvas element gradient.initGradient("#gradient-canvas"); // Control animation playback gradient.pause(); // Pause the animation gradient.play(); // Resume the animation // Toggle individual color layers (index 0-3) gradient.toggleColor(0); // Toggle first color layer gradient.toggleColor(2); // Toggle third color layer // Show/hide gradient legend gradient.showGradientLegend(); gradient.hideGradientLegend(); ``` -------------------------------- ### Initialize Gradient Canvas Source: https://github.com/jordienr/whatamesh/blob/master/README.md Include this HTML element in your page to render the gradient. CSS variables are used to define the gradient colors. ```html ``` -------------------------------- ### Dynamic Play/Pause and Intersection Observer Source: https://context7.com/jordienr/whatamesh/llms.txt Implement play/pause functionality for the gradient animation using button clicks and optimize performance by pausing the animation when the canvas is not in view using an Intersection Observer. ```javascript import { Gradient } from "whatamesh"; const gradient = new Gradient(); gradient.initGradient("#gradient-canvas"); // Create play/pause toggle button const toggleButton = document.getElementById("toggle-btn"); let isPlaying = true; toggleButton.addEventListener("click", () => { if (isPlaying) { gradient.pause(); toggleButton.textContent = "Play"; } else { gradient.play(); toggleButton.textContent = "Pause"; } isPlaying = !isPlaying; }); // Pause when element is not visible (performance optimization) const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { gradient.play(); } else { gradient.pause(); } }); }); observer.observe(document.getElementById("gradient-canvas")); ``` -------------------------------- ### Implement Full Page Animated Gradient Background Source: https://context7.com/jordienr/whatamesh/llms.txt Uses a fixed-position canvas element behind content with CSS custom properties for gradient colors. Includes a toggle mechanism to pause or play the animation via the JavaScript API. ```html
Beautiful animated mesh gradient background